简体   繁体   English

如何通过javascript从父窗口访问子窗口?

[英]How to access child window from parent window through javascript?

Suppose we open a popup through javascript when a link is clicked on parent window. 假设我们在父窗口上单击链接时通过javascript打开一个弹出窗口。

As everybody knows that parent window elements can be accessed from child window using the window.opener() function. 众所周知,可以使用window.opener()函数从子窗口访问父窗口元素。

Is it possible to do exactly reverse ? 有可能完全反转吗? Can parent window access the information about the child window ? 父窗口可以访问有关子窗口的信息吗?

When you open a window through javascript's window.open() function it returns you a reference of the child window. 当您通过javascript's window.open()函数打开一个window ,它将返回您对子窗口的reference

Using this reference you can access elements of the child window, required it complies with Same origin policy security requirements. 使用此参考,您可以访问子窗口的elements ,前提是它符合“ 相同来源策略”的安全要求。

You mean something like this: 你的意思是这样的:

a=window.open()
a.document.write("<div id='mydiv'>test</div>")
a.document.getElementById("mydiv")

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

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