1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <html> <head> <title>Simple Barcode Scanner</title> <script> var barcode = ''; var interval; document.addEventListener('keydown', function(evt) { if (interval) clearInterval(interval); if (evt.code == 'Enter') { if (barcode) handleBarcode(barcode); barcode = ''; return; } if (evt.key != 'Shift') barcode += evt.key; interval = setInterval(() => barcode = '', 20); }); function handleBarcode(scanned_barcode) { document.querySelector('#last-barcode').innerHTML = scanned_barcode; } </script> </head> <body> <h1>Simple Barcode Scanner</h1> <strong>Last scanned barcode: </strong> <div id="last-barcode"></div> </body> </html> |