//重写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(name){
var iframe = document.createElement("IFRAME");
iframe.style.display="none";
iframe.setAttribute("src", 'data:text/plain,');
document.documentElement.appendChild(iframe);
var result = window.frames[0].window.confirm(name);
iframe.parentNode.removeChild(iframe);
return result;
}
重写alert和confirm方法
本文介绍了一种在网页中重写alert和confirm方法的方法,通过创建并立即移除一个隐藏的iframe,可以在不显示URL的情况下弹出警告框或确认框,避免了地址栏泄露的问题。
436

被折叠的 条评论
为什么被折叠?



