如果你像这样改变本机函数:
window.open= function (a,b,c)
{
alert(2);
}
然后你就可以
delete window.open
它会恢复原来的功能,但是:
如果你像这样改变它的原型:
window.__proto__.open= function (a,b,c)
{
alert(3);
}
then delete
不会做任何事情=\有什么想法现在如何恢复它吗?
当你改变时window.open
到其他事情,例如使用window.open = 'something else';
,那么你就是影子 the open
原型中的方法;
// Looking up window.open (in the prototype chain)....
window.open; // Found, result == 'something else'
window.__proto__.open; // Not accessible any more (shadowed by previous line)
调用后delete window.open
删除'something else'
,原来的方法再次变得可见,因为它从未从原型链中消失。
但如果你修改了open
原型上的方法,例如window.__proto__.open = bogus;
,那么你就不能轻易恢复旧方法了。因此,要再次获得“打开窗口”行为,您需要在替换原始方法之前保留对原始方法的引用,
var original_open = window.open;
window.__proto__.open = 'bogus';
// .... whatever ....
// Now restore it:
window.__proto__.open = original_open;
或者从别人那里借用window
,例如使用临时新框架:
var frame = document.createElement('iframe');
document.body.appendChild(frame);
window.__proto__.open = frame.contentWindow.open;
frame.parentNode.removeChild(frame);
但这整个想法很荒谬:你不应破坏内置方法.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)