做了一个供移动端调用的html,测试时发现confirm提示时显示ip。
解决方法:
在js的最前面加上如下代码即可:
//重写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 不显示ip地址
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;
}
var result = iwindow.confirm(message);
iframe.parentNode.removeChild(iframe);
return result;
}
catch (exc) {
return wConfirm(message);
}
}

博客讲述做移动端调用的HTML时,测试发现confirm提示显示IP的问题,并给出解决办法,即在js最前面添加特定代码。
1053





