简体   繁体   English

如何从父窗口访问子窗口URL?

[英]How To Access Child Window URL from Parent Window?

I am redirecting my child window to another url after launching. 启动后,我将子窗口重定向到另一个URL。 Actually I am submitting the data to another domain. 实际上,我正在将数据提交到另一个域。 That domain processing the data and sends to new domain. 该域处理数据并发送到新域。 I need to catch the new domain URL. 我需要捕获新的域URL。

I don't think you'll be able to do that. 我认为您将无法做到。 You can't access frames/windows from different origin - that's simply not safe and the browser won't let you. 您无法访问来自其他来源的框架/窗口-这绝对不安全,浏览器也不允许您访问。

You could try to work it out differently. 您可以尝试以其他方式解决。

For example, I believe you could have your server side get the other website for you and serve it in your own domain. 例如,我相信您可以让服务器端为您获得另一个网站并在您自己的域中提供服务。 If you decide to do that, you need to have the reference to your child window first (eg var win = window.open(url); ) - but still, that needs to be in your domain. 如果您决定这样做,则需要先引用您的子窗口(例如var win = window.open(url); ),但仍然需要在您的域中。

Another way would be to simply post your data using your server side language and then try to read the received page (also using server side). 另一种方法是简单地使用服务器端语言发布数据,然后尝试读取接收到的页面(也使用服务器端)。 In PHP for example, you could accomplish that with cURL and Simple HTML Dom Parser . 例如,在PHP中,您可以使用cURLSimple HTML Dom Parser完成此操作。

Edit 编辑

Just came upon window.postMessage functionality. 刚遇到window.postMessage功能。 If the other websites are yours, I think that's the way to go (well, maybe except the limited compatibility in IE 8 & 9: Can I use postMessage ). 如果其他网站是您的,那么我认为这是要走的路(嗯,也许除了IE 8和9的有限兼容性: 我可以使用postMessage )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM