iframe / Popup重定向开启窗口 [英] Iframe/Popup redirecting opener window

查看:138
本文介绍了iframe / Popup重定向开启窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页位于x.com。在此页面上有一个按钮,当单击该按钮时,将启动一个新窗口(使用javascript的window.open()方法)到位于z.com的页面。弹出窗口做了一些事情,然后根据弹出窗口中定义的一些参数将原始窗口(opener,x.com)重定向到不同的页面。

I have a page located at x.com. On this page is a button that, when clicked, will launch a new window (using javascript's window.open() method) to a page that is located at z.com. The popup does a few things, then redirects the original window (the opener, x.com) to a different page based on some parameters defined in the popup.

这个工作原理在Firefox / Chrome中很好,但在IE中却没有。在IE中(具体为8,但我相信7也有此问题)原始窗口(开启者)未被重定向。相反,会出现一个新窗口并重定向该窗口。

This works fine in Firefox/Chrome, but not in IE. In IE (8 specifically, but I believe 7 also has this problem) the original window (the opener) is not redirected. Instead, a new window comes up and THAT window is redirected.

我尝试了许多不同的方法来尝试使其工作,包括将弹出窗口更改为iframe加载到页面上并在弹出窗口/ iframe调用的开启器上有一个函数。问题似乎是IE拒绝允许跨域网站通过javascript互相交谈。

I've tried many different methods to try and get this to work, including changing the popup to an iframe loaded on the page and having a function on the opener that the popup/iframe call. The problem seems to be that IE refuses to allow cross-domain sites to talk to each other via javascript.

有没有办法解决这个问题?如何根据弹出窗口或iframe中的参数将父窗口重定向到页面?

Is there a way around this? How can I get the parent window to redirect to a page based on parameters in a popup or iframe?

编辑:

以下是一些示例代码:

在domainA.com上的一个页面中,我有:

In a page on domainA.com, I have this:

<img src='/images/test.png' onclick="window.open('http://www.domainB.com/item.aspx', 'name', 'width=100,height=100,menubar=no,status=no,toolbar=no');" />

在domainB.com上的item.aspx中,我在javascript中有这个:

In item.aspx on domainB.com I have this in the javascript:

opener.location.href = 'http://www.somethingelse.com/';

在Firefox / Chrome中,这很好用。在IE中,当domainB.com尝试在开启者(也就是父窗口,即domainA.com)上设置location.href时,它会打开一个新窗口,这不是我想要的。我希望它将开启者(父窗口)重定向到我指定的URL。

In Firefox/Chrome, this works fine. In IE, when domainB.com tries to set location.href on opener (aka the parent window, which is domainA.com), it instead opens a new window, which is not what I want. I want it to redirect the opener (parent window) to the URL I specified.

Bara

推荐答案

我最后通过执行以下操作来解决它:

I ended up resolving it by doing the following:

我在主页面添加了一个iFrame。 iFrame与我的弹出窗口位于同一个域中。 iFrame包含一个按钮,单击该按钮将启动弹出窗口。

I added an iFrame to my main page. The iFrame is in the same domain as my popup. The iFrame contains a button that, when clicked, will launch the popup.

弹出窗口就是这样,然后将iFrame的hash标签更改为#change(所以url将是www.whatever.com/iframe.aspx#change) 。在iFrame的javascript中,我有一个循环,检查哈希是否显示更改,如果是,它会将父页面重定向到我想要的任何地方。这很好用。

The popup does it's thing, then changes the iFrame's hash tag to something like #change (so the url would be www.whatever.com/iframe.aspx#change). In the iFrame's javascript, I have a loop going that checks the hash to see if it says "change" and if so, it will redirect the parent page to wherever I want. This works beautifully.

因为我不想在每一页上都有无限循环,所以我会进行浏览器检查,以便这只适用于IE。对于所有其他浏览器,我只使用window.opener工作正常。

Because I did not want the infinite loop on every single page, I do a browser check so that this only applies to IE. For all other browsers I just use window.opener which works fine.

Bara

这篇关于iframe / Popup重定向开启窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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