我有以下脚本在Google Script HTML服务中运行。计划是在我们的Android手机上使用它来调用Zxing QR扫描仪,然后从扫描中返回值。然后我会有脚本将QR放入Google电子表格中。在Android设备上运行Google Apps脚本HTML时,此脚本会引发错误。谢谢你的帮助!
<html>
<body style="margin:0px;font-family:tahoma" onhashchange="getHash()">
<input id=barcode type=text >
<input style="width:100px;height:100px" type=button value="Scan" onclick="getScan()">
<p id="message"></p>
<script type="text/javascript" >
function getScan(){
var href=window.location.href;//works
var ptr=href.lastIndexOf("#");
if(ptr>0){
href=href.substr(0,ptr);
}
window.location.href="zxing://scan/?ret="+escape(href+"#{CODE}");
}
var changingHash=false;
function getHash(){
if(!changingHash){
changingHash=true;
var hash=window.location.hash.substr(1);
document.getElementById('barcode').value=unescape(hash);
window.location.hash="";
changingHash=false;
}else{
message.innerHTML = "Input " + document.getElementById('barcode').value;
//Do something with barcode here
}
}
</script>
<body>
</html>