如何从父窗口访问子窗口URL? [英] How To Access Child Window URL from Parent Window?

查看:151
本文介绍了如何从父窗口访问子窗口URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动后,我将子窗口重定向到另一个URL.实际上,我正在将数据提交到另一个域.该域处理数据并发送到新域.我需要捕获新的域URL.

I am redirecting my child window to another url after launching. 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.

推荐答案

我认为您无法做到这一点.您无法访问来自不同来源的框架/窗口-这绝对不安全,浏览器也不允许您访问.

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.

例如,我相信您可以让您的服务器端为您获得另一个网站并在您自己的域中提供服务.如果您决定这样做,则需要先引用您的子窗口(例如var win = window.open(url);),但是仍然需要在您的域中.

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 (e.g. var win = window.open(url);) - but still, that needs to be in your domain.

另一种方法是简单地使用服务器端语言发布数据,然后尝试读取接收到的页面(也使用服务器端).例如,在PHP中,您可以使用 cURL

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.

刚实现了 window.postMessage 功能.如果其他网站是您的,那我认为这是要走的路(好吧,也许除了IE 8和9的有限兼容性外: nofollow>我可以使用postMessage ).

Just came upon window.postMessage functionality. 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).

这篇关于如何从父窗口访问子窗口URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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