alert,confirm弹出框显示URL问题,将URL去掉

/*remove url of alert/confirm*/
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);
}
}

posted @ 2016-11-23 14:57  eric_z  阅读(6200)  评论(0编辑  收藏  举报