- 加入我的QQ群
- 关注我的百家号
扫描下面的二维码,“关注”我的百家号。
在做网站开发 或 移动端webapp开发时,我们会经常用到JS的alert和confirm弹窗。在电脑端和android安卓手机上,alert和confirm显示都是正常的,不显示url地址,而唯独在苹果ios系统中会显示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地址了。