Austin Mauldin February 2016

Store QR scanned URLs in JavaScript

I'm using this plugin for Cordova to scan QR codes. The QR scanner is triggered when a "scan QR code" button is clicked inside the app. The barcode scanner plugin works great. Now, I'm trying to store those values scanned as variables in Javascript.
The plugin itself uses this function:

function startScan() {
cordova.plugins.barcodeScanner.scan(
function (results){
    var s = "Result: " + result.text + "<br/>" +
    "Format: " + result.format + "<br />" +
    "Cancelled: " + result.cancelled;
    resultDiv.innerHTML = s;
},
function (error) {
    alert("Scanning failed: " + error);
}
)

Where resultDiv is a global variable and is initailized as follows:

document.querySelector("#startScan").addEventListener("touchend", startScan, false);
resultDiv = document.querySelector("#results");

As I mentioned the scanning works fine, but my results page is blank(except for the header) after testing. The results page is as follows:

<div data-role="page" id="pagethree"  style="text-transform:none">
        <div align="center">
            <div id="results">
            <h1>Report</h1>
            </div>
        </div>
    </div>

How would you represent QR codes(URLs) in html where the there is no limit of QR codes?

Answers


Mat'arangéÇa February 2016

The param results of your inner function never get used in your sample.

function startScan() {
    cordova.plugins.barcodeScanner.scan(
        function (results){
            var s = "Result: " + results.text + "<br/>" +
            "Format: " + results.format + "<br />" +
            "Cancelled: " + results.cancelled;
            resultDiv.innerHTML = s;
        },

        function (error) {
            alert("Scanning failed: " + error);
        })};

Post Status

Asked in February 2016
Viewed 1,686 times
Voted 11
Answered 1 times

Search




Leave an answer