在安卓手机中扫描二维码后停止Instascan警报

3

我有一个应用程序,使用instascan扫描QR码,但每次在安卓手机上扫描QR码时都会弹出一个包含解码结果的警告框。例如,如果我生成了一个文本为“I like bananas”的QR码,则警告框会显示“https://mywebsite.com says 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>

感谢任何帮助。

1个回答

0

我根据这篇文章找到了答案:如何在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);
            }
        });

如果您不需要返回任何内容,那么可以像这样留空:options.success = function (result) { } - Sarah Cox

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接