Help with QR Code reader in Cordova

Asked

Viewed 791 times

2

I’m trying to make the app (Cordova + Onsen) read a QR Code and when reading open the link contained in the QR, but instead open the link it tries to open a page at the application root (file://android_asset/www/Barcode.result).

In the code I just added the var ref = window.open('barcode.result', '_blank'); the rest is working normally, just does not open the link contained in the QR.

Follow my controller code:

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'); //parte acrescentada
            });
        },
        function (error) {
            alert("Scanning failed: " + error);
        }
    )};
});

3 answers

1

var ref = window.open(barcode.result, '_blank');

without '' when referencing the variable barcode.result

  • I tried, but then nothing happens, it goes back to the screen with the button to scan the QR...

0

I was able to make it work, what was missing was to save the result of QR in a variable and then use the result of this variable to open the site.

0

Good, use the terminal, navigate to your Cordova application folder and install the Inappbrowser plugin:

cordova plugin add org.apache.cordova.inappbrowser

Then in your code when you want to open the system browser use the target _system

window.open('http://google.com', '_system');

or

<a href="http://google.com" target="_system"> abrir browser do sistema </a>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.