locked
error while call java script RRS feed

  • Question

  • User-1878002066 posted
    JavaScript critical error at line 9, column 38 in http://localhost:52967/js/app.js\n\nSCRIPT1002: Syntax error

    Code:
    const
    qrCodeScannerBtn = document.getElementById('Btn'); const qrCodeScannerText = document.getElementById('Text'); const qrCodePreview = document.getElementById('preview'); const scanner = new Instascan.Scanner({ video: qrCodePreview, mirror: false }); scanner.addListener('scan', content => { qrCodeScannerText.value = content; scanner.stop(); }); qrCodeScannerBtn.addEventListener('click', () => { if (scanner._scanner._active) { return scanner.stop(); } Instascan.Camera.getCameras() .then(function(cameras) { if (cameras.length) { const camera = cameras[cameras.length - 1]; scanner.start(camera); console.log(scanner); } else { alert('No cameras found.'); } }) .catch(function(e) { console.error(e); }); });
    Tuesday, August 7, 2018 10:10 AM

All replies

  • User-474980206 posted
    You are using es2015 syntax. Be sure the browser supports. Should work in chrome or edge, but not any version of IE.
    Wednesday, August 8, 2018 12:44 AM
  • User1724605321 posted

    Hi onenews,

    Or you could try to modify the ECMAScript to standard way :

    scanner.addListener('scan',  function(content) {})
    
    qrCodeScannerBtn.addEventListener('click', function() {})

    Best Regards,

    Nan Yu

    Wednesday, August 8, 2018 5:19 AM