从Web应用程序中的任何网页捕获扫描的条形码

在我inheritance的webapp中,有一些jquery代码可以捕获条形码扫描(简单的一维条码,如健身俱乐部和杂货店使用 – 没有QR码,没有异国情调等)。 但实现它的方式需要一个模态框来设置一个微调器,然后你扫描,它的工作原理。 我们的客户不喜欢这样。 他们希望能够从应用程序中的任何网页扫描条形码,而不必转到某个页面并在扫描之前出现模式窗口,阻止其他所有内容。

我感兴趣地看了这个: https : //github.com/julien-maurel/jQuery-Scanner-Detection (我无法让它工作。)我在网页上尝试过这个:

  $(window).bind('scannerDetectionComplete', function (e, data) { alert(e); alert(data); })  

我也试过$(document).bind(...)代替

实际的源文档只是说要做$(selector).scannerDetection(); 他们没有提供实际使用的例子。

我真的不在乎我是否使用这个jquery插件,一些其他jquery插件,自定义jquery或一些原始的javascript代码片段 – 我只需要能够从任何网页检测条形码扫描而不需要求助于模态监听器的东西。 如果有人知道如何使用“jQuery-Scanner-Detection”插件(如上所述),我也很乐意尝试。 谢谢。

文件准备好;)

 jQuery(document).ready(function($) { $(window).scannerDetection(); $(window).bind('scannerDetectionComplete',function(e,data){ alert('complete '+data.string); }) .bind('scannerDetectionError',function(e,data){ console.log('detection error '+data.string); }) .bind('scannerDetectionReceive',function(e,data){ console.log(data); }) $(window).scannerDetection('success'); }); 

这是我使用它的方式,它工作正常:

 $(selector).scannerDetection(function(data) { onComplete: //whatever you want }); 

我不认为有必要将它绑定到您的窗口或文档,您可以直接使用您的选择器。