我有一个使用instascan扫描二维码的应用程序,但每次你在android手机上扫描二维码时,都会弹出一个带有解码结果的警报。例如,如果我生成了一个文本为"I like bananas“的二维码,则警报将显示"https://mywebsite.com say I like bananas”。
有什么方法可以阻止显示此警报吗?这不会发生在我的笔记本电脑或平板电脑上,只会发生在我的手机上。这是我的代码,如果你想看的话:
<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>任何帮助都是非常感谢的。
发布于 2021-03-12 07:01:13
我根据这篇文章找到了答案:Stop alert javascript popup in webbrowser c# control
我想从一个名为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);
}
});https://stackoverflow.com/questions/66555766
复制相似问题