调用已被“擦除"的本地javascript函数.通过网页 [英] Call native javascript function that has been "erased" by the web page

查看:40
本文介绍了调用已被“擦除"的本地javascript函数.通过网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说一个网页做了这样的事情:

Let's say a web page did this:

window.alert = console.info;

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

How can I, through browser console, recover the original alert method to get the modal back?

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

I tried accessing the window.prototype but it does not exist. I would also like to know if such process exist in general (like, if String.* was erased/redefined by a website or if website made a console.log = window.alert).

推荐答案

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

What you can do, is create an iframe attach it to page and then copy alert method from that 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函数.通过网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆