Lam*_*mmy 2 javascript iframe dom popup
我试图使用弹出窗口的脚本文件中的window.opener引用来访问弹出窗口的开启器.
请考虑popup.html中包含的以下脚本:
http://localhost/test/popup.html
Run Code Online (Sandbox Code Playgroud)<script> alert(window.opener.test_dom); </script>
如果不涉及iframe,我们会看到来自popup.html的警告消息:
http://localhost/test/base.html
Run Code Online (Sandbox Code Playgroud)<html> ... <script> var test_dom = 'test_dom'; var popup = window.open("http://localhost/test/popup.html",... </script> </html>
存在3个文件时存在问题..一个包含iframe的容器页面,从iframe中启动弹出窗口.当弹出窗口出现时,这不会显示警告消息:
C:\ TestContainer\container.html
Run Code Online (Sandbox Code Playgroud)<html> ... <iframe src="http://localhost/test/base.html"> <script> var test_dom = 'test_dom'; var popup = window.open("http://localhost/test/popup.html",... </script> <iframe> </html>
也许这是一个安全限制?AFAIK base.html和popup.html属于同一个域,因此我认为没有理由这样做.是否还有其他方法可以通过popup.html脚本中的其他DOM属性访问opener?我已经坚持了一天了.
除了对开启者的引用之外,其他一切似乎在所有脚本中都按预期工作.
使用IE 11.
任何帮助表示赞赏!
一个iframe没有window.opener.它有一个window.parent(嵌入iframe的窗口).如果父级确实是顶级窗口,那么也许该窗口具有window.openerif它的实际弹出窗口.
您没有显示您的具体HTML情况,但也许您想从iframe中得到的是:
window.parent.opener
Run Code Online (Sandbox Code Playgroud)