Skip to content

Instantly share code, notes, and snippets.

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 johanbaaij/63f8c695570d4ab44f7dfb34ea89c78d to your computer and use it in GitHub Desktop.
Save johanbaaij/63f8c695570d4ab44f7dfb34ea89c78d to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Basic Barcode Reader</title>
<script type="text/javascript" src="BarcodeReader.js"></script>
<script type="text/javascript">
var defaultScanner;
// On page load create a BarcodeReader object
function setup ()
{
defaultScanner = new BarcodeReader(null,
onBarcodeReaderComplete);
}
// After BarcodeReader object is created we can configure our
// symbologies and add our event listener.
function onBarcodeReaderComplete ( result )
{
if (result.status == 0)
{
// BarcodeReader object was successfully created.
// Configure the symbologies needed.
defaultScanner.set("Symbology", "Code39", "Enable",
"true", onSetComplete);
defaultScanner.set("Symbology", "Code128", "EnableCode128",
"true", onSetComplete);
// Add an event handler for the barcodedataready event
defaultScanner.addEventListener("barcodedataready",
onBarcodeDataReady, false);
}
else
{
defaultScanner = null;
alert('Failed to create BarcodeReader, '
+ result.message);
}
}
// Verify the symbology configuration.
function onSetComplete ( result )
{
if (result.status != 0)
{
alert('set Family: ' + result.family + ', Key: ' +
result.key + ', Option: ' + result.option +
', Value: ' + result.value + 'failed. ' +
result.message);
}
}
// Handle barcode data when available.
function onBarcodeDataReady (data, type, time)
{
document.getElementById("BarcodeData").value = data;
document.getElementById("SymbType").value = type;
document.getElementById("ReadTime").value = time;
}
</script>
</head>
<body onload="setup();">
<label for="BarcodeData">Data:</label>
<input type="text" id="BarcodeData" size=12/><br>
<label for="SymbType">Symbology:</label>
<input type="text" id="SymbType" size=12/><br>
<label for="ReadTime">Time:</label>
<input type="text" id="ReadTime" size=12/><br>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment