条形码扫描在智能手机/平板电脑浏览器的web应用程序
barcode scanning in web apps for smartphone/tablet browsers
我在android设备的web应用程序中使用zxing://scan进行条形码扫描。用户不能接受phonegap的包装。他们希望应用程序只能通过浏览器访问。但是根据我的理解,zxing://scan不能是Ajax请求url。我通过的唯一解决方案是window.location.href = zxing://scan/?ret="+escape(window.location.href+"?val={CODE}
,它将调用android条形码扫描仪并将条形码值分配给url中的{CODE}占位符。但不久之后,页面重新加载,所有数据都丢失了。表单太长,有多个网格。除了存储用户在会话中输入的所有数据并在每次用户扫描条形码时重新加载并将其设置回表单之外,是否有任何快速的工作可以将值设置为浏览器选项卡的url栏并防止触发页面重新加载?
请注意:没有页面重新加载&客户端不能接受任何phonegap插件。我真的是命中注定还是有解决办法?
我的第二种方法是使用相机标签<input id="demoFile" type="file" accept="image/*;capture=camera">
拍摄条形码的照片,base64编码&向服务器端发送一个帖子,解码条形码,并从其响应中获取条形码值。我知道这不是条形码扫描的最佳方式。但由于我上面提到的原因,我运气不好。你如何评价这种方法?有比这更好的解决办法吗?
根据应用程序,与其在?val=触发返回值,不如将其发送到#val=并使用javascripts document.location.hash解析它。如果你听了onhashchange事件(假设它是一个较新的浏览器或移动设备),你就可以在不刷新页面的情况下做事情了。
一个被请求的例子(假设使用jQuery):
$(window).one('hashchange', function() {
if(document.location.hash.match('=')){
//we have a code...
var code = document.location.hash.substr(document.location.hash.indexOf('=')+1));
document.location.hash="";
//now do something with scanned code
alert(code);
}
});
var selector = 'body';
var filler = "<p align='center'>This device is not set up to support scanning at the moment.<br><br>"
+"On Android devices, install the <a href='https://play.google.com/store/apps/details?id=com.google.zxing.client.android&feature=search_result'>Barcode Scanner by ZXing</a> app from the Google Play store.<br><br>"
+"You can also manually enter your barcode here: <input type='text' id='code'><input type='button' id='submitcode' value='Check Barcode'>";
+"</p>";
//Set up our html into the element specified in the selector var
$(selector).html("<iframe id='scanner'></iframe>"+filler);
//try to load the zxing app if it exists - if not, error will catch the failed load and default us back to the manual entry form
$('#scanner').error(function(){
$(selector).html(filler);
//if manual form is submitted, append the hash so we can use the one set of logic to manage the codes
$(selector+' #submitcode').click(function(){ document.location.href = document.location.href+"#sku="+$('#code').val(); });
//catch someone hitting return to submit the form as well
$('#code').keydown(function (e){
if(e.keyCode == 13){
$(selector+' #submitcode').click();
}
});
}).attr('src',"zxing://scan/?ret="+escape(window.location.href+"#sku={CODE}"));
//handle manual form submission via button click or return key
$(selector+' #submitcode').click(function(){
document.location.href = document.location.href+"#sku="+$('#code').val();
});
$('#code').keydown(function (e){
if(e.keyCode == 13){
$(selector+' #submitcode').click();
}
});
- Windows形成web浏览器控件和Javascript更改的DOM
- 如何将javascript事件从web浏览器wpf控件发送到wpf的c#代码
- 将下载链接从web浏览器传递给第三方应用程序
- 如何允许web浏览器记住未以标准方式发送的表单字段
- web浏览器中的离线应用程序存储数据并在之后上传
- 如何使用web浏览器在NoSQL数据中呈现换行符
- 创建web服务“;活动指示器”-与所有浏览器兼容的类似指示符
- 从web浏览器通过javascript向侦听TCP端口5500的本地应用程序发送json命令
- web应用程序中的跨浏览器会话
- Web浏览器扩展名通用文件
- 将web浏览器客户端输入传递给服务器Java源代码
- 如何在关闭浏览器后自动登录到web应用程序
- 在 Web 浏览器中优先下载图像的技术
- Web 工作线程中的同步 XHR 请求是否仍会锁定浏览器
- Phonegap打开表单提交到Web浏览器上的外部域
- 如何防止 C# Web 浏览器中的脚本错误
- Web 浏览器中的硬刷新和数据持久性
- 用户输入的javascript不如浏览器web开发工具安全
- JavaScript Timer类:在浏览器web控制台中未定义的方法
- 节点无浏览器web客户端,可以管理cookie