苹果ios系统中,不让alert和confirm弹窗中显示url地址

苹果ios系统中,不让alert和confirm弹窗中显示url地址

我们可以通过JS来重写alert和confirm弹窗的代码来实现。代码如下:

重写alert方法:

window.alert = function(name){
var iframe = document.createElement("IFRAME");
iframe.style.display="none";
iframe.setAttribute("src", 'data:text/plain,');
document.documentElement.appendChild(iframe);
window.frames[0].window.alert(name);
iframe.parentNode.removeChild(iframe);
};

重写confirm方法:

window.confirm = function (message) {
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 result = alertFrame.window.confirm(message);
iframe.parentNode.removeChild(iframe);
return result;
};

重写后的alert和confirm弹窗,在ios系统中就不会再显示url地址了。

发布了5 篇原创文章 · 获赞 4 · 访问量 539

猜你喜欢

转载自blog.csdn.net/wozhongmingyue/article/details/103010821
今日推荐