Created
May 3, 2019 15:10
-
-
Save liketaurus/740bde966832947b39afe06d58e6114d to your computer and use it in GitHub Desktop.
How to scan QR-code using JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script src="https://rawgit.com/schmich/instascan-builds/master/instascan.min.js"></script> | |
<video id="preview" height="160" style="border: 1px solid black"></video> | |
<p id="results"></p> | |
<script type="text/javascript"> | |
let scanner = new Instascan.Scanner({ video: document.getElementById('preview') }); | |
scanner.addListener('scan', function (content) { | |
$('#results').html(content); | |
}); | |
Instascan.Camera.getCameras().then(function (cameras) { | |
if (cameras.length > 0) { | |
scanner.start(cameras[0]); | |
} else { | |
alert('No cameras found.'); | |
} | |
}).catch(function (e) { | |
alert(e); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment