弹窗如何改变其父跨域的页面位置?
我希望有人能帮助我。
我有一个网站,它使用 javascript 打开另一个域中存在的弹出窗口。
在弹出窗口中,我想要一个“立即预订”链接/按钮,它将父网站的页面更改为其 booking.htm 页面,然后弹出窗口关闭。
无法将弹出窗口托管在与主网站相同的域中。
我尝试了两种代码类型来更改页面位置...
1)
window.opener.location.href="booking.htm"
2)
window.opener.window.location.href="booking.htm"
在 Firefox 6 和 Chrome 12 中 - 1 和 2 都可以完美工作。
在 Internet Explorer 8 中 - 方法 1 导致父窗口抛出一个黄色弹出栏,为用户提供暂时允许弹出窗口的选项。方法2 在弹出窗口中给出“页面错误”并给出解释“权限被拒绝”。
在 Opera 11.51 中 - 两种方法都会在错误控制台中抛出错误“未捕获的异常:ReferenceError:安全错误:试图写入受保护的变量”
我很确定这些问题与主网站和弹出窗口位于不同的位置有关域,但同样不能将它们托管在同一域上。
所以我问..
- 有没有办法让弹出窗口上的代码更改其页面位置 当他们位于不同域时,父级可以跨浏览器工作吗?
- 为什么 Internet Explorer 在方法 1 中抛出黄色弹出栏,当 我没有使用window.open,而是使用location.href?即我是 要求家长更改位置而不是打开新的弹出窗口。
- 我错过了使用某种“target=”代码吗?
- 我是否需要使用某种“return false;”或者什么?
[我在这里有一个示例,但现在已将其删除,因为我设置了一个额外的网络托管帐户来显示实际的跨域问题。但我现在不需要额外的网络主机,所以我取消它以省钱。对于给您带来的不便,我们深表歉意]
感谢您阅读本文,即使您无法提供帮助。
戴夫
I hope someone can help me.
I have a website that uses javascript to open a popup that exists at another domain.
On the popup, I want a "book now" link/button that will change the page of the parent website to it's booking.htm page, and then the popup closes.
There is no possibility of hosting the popup on the same domain as the main website.
I have tried two code types to change the page location...
1)
window.opener.location.href="booking.htm"
2)
window.opener.window.location.href="booking.htm"
In Firefox 6 and Chrome 12 - Both 1 and 2 work perfectly.
In Internet Explorer 8 - Method 1 causes the parent window to throw a yellow popup bar, giving the user option to temporarily allow popups. Method 2 gives an "Error on Page" on the popup window and gives the explanation "Permission Denied".
In Opera 11.51 - Both methods throw an error in the Error Console of "Uncaught exception: ReferenceError: Security error: attempted to write protected variable"
I'm pretty sure that the issues are to do with the main website and the popup being on different domains, but again hosting them on the same domain is not an option.
So I'm asking..
- is there a way for code on a popup to change the page location of its
parent when they are on different domains, that works cross browser? - why does Internet Explorer throw a yellow popup bar in method 1, when
I'm not using using window.open, I'm using location.href? i.e. I'm
asking the parent to change location not open a new popup. - have I missed out using some sort of "target=" code?
- do I need to use some kind of "return false;" or something?
[I had an example here, but have now removed it as I set up an extra web hosting account to show the cross domain issue in action. But I don't need the extra web host now, so am cancelling it to save money. Sorry for the inconvenience]
Thanks for reading this far even if you can't help out.
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能这样做跨域。在子弹出页面中重定向到父级的域,并且该页面可以简单地刷新/重定向打开器,或者您可以访问它,因为它将是相同的域。
You cant do this cross domain. In child popup page redirect to the parent's domain and that page than can simply refresh/redirect the opener or you can access it as it will be same domain.