Created
April 9, 2018 09:19
-
-
Save Jignesh-Darji/8f4d7a90a10a74ec355ddebbe4a30bfc to your computer and use it in GitHub Desktop.
QR Code Scanner Using HTML
This file contains 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
<html> | |
<head> | |
<style> | |
body, input {font-size:14pt} | |
input, label {vertical-align:middle} | |
.qrcode-text {padding-right:1.7em; margin-right:0} | |
.qrcode-text-btn {display:inline-block; background:url('http://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2017/07/1499401426qr_icon.svg') 50% 50% no-repeat; height:1em; width:1.7em; margin-left:-1.7em; cursor:pointer} | |
.qrcode-text-btn > input[type=file] {position:absolute; overflow:hidden; width:1px; height:1px; opacity:0} | |
</style> | |
</head> | |
<body> | |
<input type=text size=16 placeholder="Tracking Code" class=qrcode-text><label class=qrcode-text-btn><input type=file accept="image/*" capture=environment onclick="return showQRIntro();" onchange="openQRCamera(this);" tabindex=-1></label> | |
<input type=button value="Go" disabled> | |
<script> | |
function openQRCamera(node) { | |
var reader = new FileReader(); | |
reader.onload = function() { | |
node.value = ""; | |
qrcode.callback = function(res) { | |
if(res instanceof Error) { | |
alert("No QR code found. Please make sure the QR code is within the camera's frame and try again."); | |
} else { | |
node.parentNode.previousElementSibling.value = res; | |
} | |
}; | |
qrcode.decode(reader.result); | |
}; | |
reader.readAsDataURL(node.files[0]); | |
} | |
function showQRIntro() { | |
return confirm("Use your camera to take a picture of a QR code."); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The librariy missing: