Answer the question
In order to leave comments, you need to log in
How to execute a certain code inside a tab after a successful barcode scan?
I have a local site that is opened by a person with a connected scanner and I would like to execute a certain js (modal window for example show) after the scanner successfully processes the barcode.
Tell me how the scanner works on the web (what action it can be triggered for) and how it is better to do it.
Ideally, I would like without additional libraries.
Thank you.
Answer the question
In order to leave comments, you need to log in
In 2007, I automated a mini-shop with a similar scanner. I do not remember the model (in short, the cheapest, only a USB cable and a non-switchable tweeter). No separate drivers seemed to be required, the scanner was defined as a Numpad keyboard. Actually, the scanner stupidly dialed the scanned number as on a regular keyboard. Processing an event is not a problem even in the browser, even in the terminal. Moreover, the operator can scan the code, or he can type it manually on the keyboard - and there is no difference, that is, this is much more difficult to track than just the "scan" event.
Greetings!
Just a couple of months ago, I solved such a problem, wrote a small web application for inventorying a store.
I made the following logic:
I added a global event to "keydown", and it focused on the hidden input.
on the input itself, an event is also set for pressing the "Enter" key. Since the barcode scanner, after sending the code, also emulates pressing the "Enter" key, that is, as it were, completes the input.
And already in the event at the input, on "Enter", a function is launched, in which various checks of the entered information take place.
Here is an example of a global event:
window.addEventListener("keydown", function() {
try {
if (window.editing) return;
let obj = document.getElementById("barcode");
if (window.searched) obj.value = "";
window.searched = false;
obj.focus();
} catch (e) {
console.log(e);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question