The aim here is to be able to get a scanned code from anywhere in a web page.
You can try the plugin and see if it works with your code reader
A handheld scanner is exactly like a keyboard that will quickly enter the sequence of any scanned code.
The trick is rely on the speed of entry to suspect a scan.
$ bower install jquery-code-scanner
Include the tool
<script src="js/jquery.min.js"></script>
<script src="js/jquery-code-scanner.js"></script>
<!-- ... -->
<input type="text" id="code-scan">
Initialize an input
$('#code-scan').codeScanner();
This input will receive any scanned code
-
minEntryChars
default: 8
Minimum characters entered to be considered as a code reader -
maxEntryTime
default: 100
Maximum time (in millisecond) to enter the characters to be considered as a code reader
$('#code-scan').codeScanner({
maxEntryTime: 500, // milliseconds
minEntryChars: 15 // characters
});
In this example, if 15 characters are not entered within 500ms, the string will not be taken as a scanned code
onScan
default: Function setting the code into the input
This function will be called when a code is scanned
$('#code-scan').codeScanner({
onScan: function ($element, code) {
console.log(code);
}
});