JS中去除手机端的alert弹框中的关闭网页功能

问题没有得到完全的解决,仅能解决刷新的第一次点击无关闭网页

去除关闭网页
JS中去除手机端的alert弹框中的关闭网页功能_第1张图片
具体代码如下

        var wAlert = window.alert;
        window.alert = function (message) {
            try {
                var iframe = document.createElement("IFRAME");
                iframe.style.display = "none";
                iframe.setAttribute("src", 'data:text/plain,');
                document.documentElement.appendChild(iframe);
                var alertFrame = window.frames[0];
                var iwindow = alertFrame.window;
                if (iwindow == undefined) {
                    iwindow = alertFrame.contentWindow;
                }
                iwindow.alert(message);
                iframe.parentNode.removeChild(iframe);
            }
            catch (exc) {
                return wAlert(message);
            }
        }
        var wConfirm = window.confirm;
        window.confirm = function (message) {
            try {
                var iframe = document.createElement("IFRAME");
                iframe.style.display = "none";
                iframe.setAttribute("src", 'data:text/plain,');
                document.documentElement.appendChild(iframe);
                var alertFrame = window.frames[0];
                var iwindow = alertFrame.window;
                if (iwindow == undefined) {
                    iwindow = alertFrame.contentWindow;
                }
                iwindow.confirm(message);
                iframe.parentNode.removeChild(iframe);
            }
            catch (exc) {
                return wConfirm(message);
            }
        }

你可能感兴趣的:(WEB前端,javascript,js)