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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18890599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 22:42:42  来源:igfitidea点击:

How to access child window from parent window through javascript?

javascriptjquery

提问by Kshitij Jain

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 ?

是否可以完全反向?父窗口可以访问子窗口的信息吗?

回答by Arpit Agrawal

You mean something like this:

你的意思是这样的:

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

回答by niksvp

When you open a windowthrough javascript'swindow.open()function it returns you a referenceof the child window.

当您打开一个windowthrough javascript'swindow.open()函数时,它会返回一个reference子窗口。

Using this reference you can access elementsof the child window, required it complies with Same origin policysecurity requirements.

使用此参考,您可以访问elements子窗口,前提是它符合同源策略安全要求。