gpt4 book ai didi

javascript - 网页调用已经 "erased"的原生javascript函数

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:10:05 25 4
gpt4 key购买 nike

假设一个网页做了这个:

window.alert = console.info;

我怎样才能通过浏览器控制台恢复原始的 alert 方法来取回模态?

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

最佳答案

您可以做的是创建一个 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);

关于javascript - 网页调用已经 "erased"的原生javascript函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51536124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com