<!DOCTYPE html>
<html>
<head>
<title>Scan</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
</head>
<button id="btn-open-scanner">Open Scanner!</button>
<h3>Result</h3>
<p id="result"></p>
<script type="text/javascript">
window.onload = function() {
var button = document.getElementById('btn-open-scanner');
var result = document.getElementById('result');
button.addEventListener('click', openScanner);
function openScanner() {
try {
if (typeof nativeApp !== 'undefined') {
nativeApp.scanBarcode();
} else {
webkit.messageHandlers.barcodeScanner.postMessage({});
}
} catch (e) {
alert(JSON.stringify(e));
}
}
window.onBarcodeScanned = function(barcode) {
result.innerText = barcode;
}
}
</script>
</html>