Skip to content

Instantly share code, notes, and snippets.

@kdaker
Last active May 9, 2018 19:57
Show Gist options
  • Save kdaker/d4d8fe45ff9e4c0a654aa782f1304c11 to your computer and use it in GitHub Desktop.
Save kdaker/d4d8fe45ff9e4c0a654aa782f1304c11 to your computer and use it in GitHub Desktop.
Opening a barcode scanner in the SOTG app
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<button id="button" onclick="openScanner()">Start Barcode Scanner</button>
<label>Barcode Value: <span id="barcode_value"></span></label>
<script>
function openScanner() {
// check if we are inside the SOTG application
if (window.hasOwnProperty('SOTG')) {
// open the barcode, the id argument is optional
// if you pass in an id (as a string), it will get passed back
// once the barcode is scanned.
SOTG.openBarcodeScanner("someId");
}
}
/*
* The SOTG app will call this function when barcode scanning
* is complete. It should be exposed globally (on `window`)
* @param {string} barcode the barcode value
* @param {mixed} id the string id passed in `openBarcodeScanner`, nil if no id was passed
*/
function onSOTGBarcodeScanned(barcode, id) {
document.getElementById("barcode_value").innerHTML = barcode;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment