转载自:http://www.cnblogs.com/rubylouvre/archive/2012/02/03/2335946.html
//原题目:
window.alert = function(){};______;alert(1); 填空,使后面的alert(1)能正确弹出,至少列举两种不同思路。解法一,创建新的执行环境,使用iframe沙箱window.alert = function(){};
window.alert=function(obj){
var iframe=document.createElement("iframe");
iframe.src="javascript:void(0);"
document.body.appendChild(iframe)
iframe.contentWindow.alert(obj);
}
alert(1)解法二,创建新的执行环境,打开新窗口window.alert = function(){};
window.alert = function(a){
window.open('','').alert(a)
//window.createPopup().document.parentWindow.alert(a) //IE only
}
alert(1);
本文详细介绍了两种方法来绕过window.alert()函数被重写的情况,通过创建新的执行环境,实现alert(1)的正确弹出。方法一是在页面中插入iframe作为沙箱,方法二则是打开新窗口。
2242

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



