Skip to content

Instantly share code, notes, and snippets.

@mvark
Created January 12, 2024 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvark/856c100b85f838249810f98ea6b5b406 to your computer and use it in GitHub Desktop.
Save mvark/856c100b85f838249810f98ea6b5b406 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Based on this HTML5 QR Code Reader sample by Minhaz https://blog.minhazav.dev/research/html5-qrcode.html -->
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=5">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>OFF Bar Code Scanner</title>
</head>
<body>
<div id="desc">Scan Barcode to view details on Open Food Facts</div>
<div id="reader"></div>
<!-- html5-qrcode.min.js - https://raw.githubusercontent.com/mebjas/html5-qrcode/master/minified/html5-qrcode.min.js -->
<script src="html5-qrcode.min.js" type="text/javascript"></script>
<script type="text/javascript">
function onScanSuccess(decodedText, decodedResult) {
document.getElementById('desc').innerHTML = "Barcode detected: " + decodedText + "...redirecting to Open Food Facts" ;
html5QrcodeScanner.clear();
window.location.href = "https://world.openfoodfacts.org/product/" + decodedText;
}
var html5QrcodeScanner = new Html5QrcodeScanner(
"reader", { fps: 10, qrbox: 250 });
html5QrcodeScanner.render(onScanSuccess);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment