简体   繁体   中英

Html5 and Javascript QR Scanner with JsQRScanner

I'm using JsQRScanner on a webpage to scan qr code

here is the code

  <script type="text/javascript">
function onQRCodeScanned(scannedText)
{
    var scannedTextMemo = document.getElementById("scannedTextMemo");
    if(scannedTextMemo)
    {
        scannedTextMemo.value = scannedText;
    }
}

//this function will be called when JsQRScanner is ready to use
function JsQRScannerReady()
{
    //create a new scanner passing to it a callback function that will be invoked when
    //the scanner succesfully scan a QR code
    var jbScanner = new JsQRScanner(onQRCodeScanned);
    //reduce the size of analyzed images to increase performance on mobile devices
    jbScanner.setSnapImageMaxSize(300);
    var scannerParentElement = document.getElementById("scanner");
    if(scannerParentElement)
    {
        //append the jbScanner to an existing DOM element
        jbScanner.appendTo(scannerParentElement);
    }        
}

the result in the "Scanned text" textarea.

I want open the result url immediately in the same page instead of showing it in the scanned text Thank you

You can use window.open(); javascript to open scanned URL. Suppose if your scanned URL is scannedText then you can use it like :

<script type="text/javascript">
function onQRCodeScanned(scannedText)
{
    var scannedTextMemo = document.getElementById("scannedTextMemo");
    if(scannedTextMemo)
    {
        scannedTextMemo.value = scannedText;
        window.open(scannedText); //open scanned webpage
    }
}

//this function will be called when JsQRScanner is ready to use
function JsQRScannerReady()
{
    //create a new scanner passing to it a callback function that will be invoked when
    //the scanner succesfully scan a QR code
    var jbScanner = new JsQRScanner(onQRCodeScanned);
    //reduce the size of analyzed images to increase performance on mobile devices
    jbScanner.setSnapImageMaxSize(300);
    var scannerParentElement = document.getElementById("scanner");
    if(scannerParentElement)
    {
        //append the jbScanner to an existing DOM element
        jbScanner.appendTo(scannerParentElement);
    }        
}
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM