Javascript Cordova-扫描二维码并打开链接。。。不起作用
我是编程界的新手,我正在努力让条形码扫描器在扫描后打开一个链接。 可能是我这边出了点问题,但不知道在哪里 这是我的条形码控制器代码CordovaJavascript Cordova-扫描二维码并打开链接。。。不起作用,javascript,cordova,hyperlink,phonegap-plugins,barcode-scanner,Javascript,Cordova,Hyperlink,Phonegap Plugins,Barcode Scanner,我是编程界的新手,我正在努力让条形码扫描器在扫描后打开一个链接。 可能是我这边出了点问题,但不知道在哪里 这是我的条形码控制器代码Cordova app.controller('barcodeController', function( $scope ){ $scope.barcode = { 'result': '', 'format': '', 'cancelled': '' } $scope.startScanner = function(){ cordova.plu
app.controller('barcodeController', function( $scope ){
$scope.barcode = {
'result': '',
'format': '',
'cancelled': ''
}
$scope.startScanner = function(){
cordova.plugins.barcodeScanner.scan(
function (result) {
$scope.$apply(function(){
$scope.barcode = {
'result': result.text,
'format': result.format,
'cancelled': result.cancelled
}
var ref = window.open(barcode.result, '_blank'); //line added, but not opening the QR Code website, actually it scans and do nothing...
});
},
function (error) {
alert("Scanning failed: " + error);
}
);
};
});
好的,开始工作了!正如@RaymondCamden所说,我使用了console.log,二维码扫描仪没有转储任何内容。 我必须创建一个变量来存储结果,并使用变量值打开网站。
谢谢@RaymondCamden,你的帮助太棒了 当你远程调试时,你看到了什么错误?实际上,在我扫描二维码后,它试图打开一个链接file://android_asset/www/barcode.result . 我认为它没有解析URL。使用代码var ref=window是否正确。打开'barcode.result','u blank'?不,那不对。你为什么要“打开”结果?它是一个url吗?如果是这样,则需要实际值:window.openbarcode.result,“_blank”;-barcode.result.Hi@Raymond Camden周围没有引号,谢谢,但我在这里试过了,它不起作用。是的,这是一个网址。我的代码如下:`$scope.startScanner=函数{cordova.plugins.barcodeScanner.scan函数结果{$scope.$applyfunction{$scope.barcode={'result':result.text,'format':result.format,'cancelled':result.cancelled}var ref=window.openbarcode.result,“_blank”;}`