Barcode scanner for html5 and jquery application

一个人想着一个人 提交于 2019-12-02 14:58:29

Try this code. I assum that you know about the Jquery. Run this code and type anything from the keyboard while focusing the web page and hit enter key. If this works barcode reader do the same. Configure your barcode reader to pass enter key at the end of code reading. Jquery library

<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.js'></script>

Jquery

$(document).ready(function() 
{
    var barcode="";
    $(document).keydown(function(e) 
    {
        var code = (e.keyCode ? e.keyCode : e.which);
        if(code==13)// Enter key hit
        {
            alert(barcode);
        }
        else if(code==9)// Tab key hit
        {
            alert(barcode);
        }
        else
        {
            barcode=barcode+String.fromCharCode(code);
        }
    });
});

May be you can try this https://code.google.com/p/jquery-barcodelistener/ .

It catches the barcode scanner's output and gives to you as a parameter

I found this quite old but pretty good post which was working fine with my hardware.

I have implemented it into a jquery plugin: jquery-code-scanner, you can try it here to see if it works with your code reader.

$ bower install jquery-code-scanner
<script src="js/jquery.min.js"></script>
<script src="js/jquery-code-scanner.js"></script>
<!-- ... -->
<input type="text" id="code-scan">
$('#code-scan').codeScanner();

Don't hesitate to create issues or PRs on the project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!