调用本机浏览器功能,即使它已被覆盖 [英] Call native browser function, even after it has been overridden

查看:99
本文介绍了调用本机浏览器功能,即使它已被覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有类似的东西

alert = 0;

在另一个脚本中。

这是在另一个脚本中,我的代码无法在该脚本之前加载。

This is in another script is and my code cannot load before that script.

如何调用原始的 alert 方法我的脚本?

How can I call the original alert method in my script?

推荐答案

在覆盖原始警报之前,请保存。

Before overriding the original alert, save it.

var origAlert = alert;
alert = 0;
origAlert("foo");

演示: http://jsfiddle.net/jfriend00/tnNE7/

如果可以的话保存原始值,我知道的另一种方法是访问iframe。这是一个例子:

If you can't save the original value, the only other way I know of to get access to it is in an iframe. Here's an example:

alert = 0;
var iframe = document.createElement("iframe");
iframe.height = 0;
iframe.width = 0;
document.body.appendChild(iframe);
iframe.contentWindow.alert.call(window, "foo");​

工作示例: http://jsfiddle.net/jfriend00/waMEV/

我没有在所有浏览器中尝试过此功能,但它适用于Chrome,IE和Firefox,我认为它应该适用于其他浏览器。

I haven't tried this in all browsers, but it works in Chrome, IE and Firefox and I think it should work in other browsers.

这篇关于调用本机浏览器功能,即使它已被覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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