Created
January 9, 2024 06:29
-
-
Save QuvonchbekBobojonov/322f144928cda2deeb143e6ef85af9b9 to your computer and use it in GitHub Desktop.
USB barcode scanning code in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let scan = '' | |
const lang = window.localStorage.getItem('lang', 'ru') | |
window.addEventListener('keydown', function(e) { | |
if (e.key === 'Enter') { | |
if (document.querySelector('#id_barcode')) { | |
document.querySelector('#id_barcode').value = scan | |
document.querySelector('#id_barcode').dispatchEvent(new Event('input')) | |
scan = '' | |
} else if (window.location.pathname === window.localStorage.getItem('url_main')) { | |
addCard(`/${lang}/pos/add-to-card/barcode/${scan}/`) | |
scan = '' | |
} | |
} else if (e.target.tagName === 'INPUT') { | |
scan = '' | |
} else { | |
scan += e.key | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment