gpt4 book ai didi

iframe 中的 Javascript window.opener

转载 作者:行者123 更新时间:2023-11-29 16:57:04 25 4
gpt4 key购买 nike

我正在尝试使用弹出窗口脚本文件中的 window.opener 引用来访问弹出窗口的打开器。

考虑 popup.html 中包含的以下脚本:

http://localhost/test/popup.html

<script>
alert(window.opener.test_dom);
</script>

这在不涉及 iframe 时有效,我们将看到来自 popup.html 的警告消息:

http://localhost/test/base.html

 <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

 <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.opener

你没有显示你的具体 HTML 情况,但也许你想从 iframe 中得到的是这样的:

window.parent.opener

关于iframe 中的 Javascript window.opener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31487415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com