我有一个使用instascan扫描QR码的应用程序,但是每次您在Android手机上扫描QR码时,系统都会弹出解码结果警报。例如,如果我生成带有文本“我喜欢香蕉”的QR码,则警报将显示“ https://mywebsite.com说我喜欢香蕉”。
有什么办法可以阻止此警报显示?仅在我的笔记本电脑或平板电脑上,这不会发生。这是我的代码,如果您想看的话:
<video id="preview" visible="true"></video>
<script type="text/javascript">
let scanner = new Instascan.Scanner({ video: document.getElementById('preview') });
//When a QR code is detected
scanner.addListener('scan', function (content) {
//If it is a url
if (content.match(/^http?:\/\//i)) {
//Redirect to new page
window.open(content);
} else {
var options = {};
options.url = "CameraList.aspx/GetContent";
options.type = "POST";
options.data = JSON.stringify({ content });
options.dataType = "json";
options.contentType = "application/json";
options.success = function (result) { };
options.error = function (err) { };
$.ajax(options);
}
});
</script>
任何帮助表示赞赏。
我根据这篇文章弄清楚了:在webbrowser c#控件中停止警报javascript弹出窗口
我想从名为GetContent的方法返回一个字符串,并仅在字符串不为空时才向用户发出警报:
//write a new function for alert that expects a boolean value
var fnAlert = alert;
alert = function (message, doshow) {
//only if you pass true show the alert
if (doshow === true) {
fnAlert(message);
}
}
let scanner = new Instascan.Scanner({ video: document.getElementById('preview') });
//When a QR code is detected
scanner.addListener('scan', function (content) {
//If it is a url
if (content.match(/^http?:\/\//i)) {
//Redirect to new page
window.open(content);
} else {
var options = {};
options.url = "CameraList.aspx/GetContent";
options.type = "POST";
options.data = JSON.stringify({ content });
options.dataType = "json";
options.contentType = "application/json";
options.success = function (result) {
//If my c# method GetContent returns a value
if (result != "") {
//then alert the user by passing true
alert(result, true);
}
};
options.error = function (err) { };
$.ajax(options);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句