从javascript中捕获window.open [英] Catch the window.open from javascript

查看:162
本文介绍了从javascript中捕获window.open的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页转换成html iframe,网页上有一个javascript函数来打开链接,该函数使用window.open方法打开一个新窗口。

I have a web page into a html iframe, the web page has a javascript function to open links, that function use the window.open method to open a new window.

我无法修改javascript函数(该页面是使用mapguide制作的),所以我想要在iframe之外捕获该调用,以便将新窗口的内容放入ajax模式框架中,而不是打开新窗口,这是可能的吗?

I cannot modify the javascript function (the page is made with mapguide), so I want to catch that call outside of the iframe to put the content of the new window into an ajax modal frame, instead of open a new window, is this possible?

推荐答案

尽管我不会推荐这样做,但您可以覆盖 window.open 函数,假设你的页面和iframe在同一个域中,以避免XSS安全错误。

While I would not recommend this in general, you can overwrite the definition of the window.open function in the iframe, assuming your page and the iframe are in the same domain to avoid XSS security errors.

HTML:

<iframe id="myFrame" src="...">
</iframe>

javascript在父窗口中:

javascript in the parent window:

var frame = document.getElementById('myFrame');

if (frame) {
    frame.contentWindow.open = function (url, windowName, windowFeatures) {
        // do whatever you want here (e.g. open an ajax modal frame)
    };
}

这篇关于从javascript中捕获window.open的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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