调用已被网页“擦除”的原生javascript函数

Xen*_*nos 6 javascript

假设一个网页是这样做的:

window.alert = console.info;

如何通过浏览器控制台恢复原始alert方法以恢复模态?

我尝试访问,window.prototype但它不存在。我还想知道这样的过程是否普遍存在(例如,是否String.*被网站删除/重新定义,或者网站是否制作了console.log = window.alert)。

小智 3

您可以做的是创建一个 iframe 将其附加到页面,然后从该 iframe 复制警报方法

//someone did this
window.alert = null;

//you are doing this
var frame = document.createElement('iframe');
document.body.appendChild(frame);
window.alert = frame.contentWindow.alert.bind(window);
document.body.removeChild(frame);
Run Code Online (Sandbox Code Playgroud)