gpt4 book ai didi

javascript - 使用 Chrome 访问全局变量

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:11 26 4
gpt4 key购买 nike

我有一个带有 iframe 的简单 html 代码,我想访问父级 iframe 之外的全局变量。

有人知道为什么 chrome 不想让我开心吗? :)

iframe 的代码在 ff 中工作正常,即...但在 chrome 中不工作。

HTML 代码:

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script> var one = "two"; </script>
.....
<body>
<iframe name="process" id="process" src="" frameborder=1></iframe>
</body>
</html>

iframe 代码:

<html>
<head>
<script> alert("Inside step 1 : "+parent.one); </script>
</head>
<body>
STEP 1
</body>
</html>

最佳答案

不幸的是,您不能在 JavaScript 中执行此操作。每个 iframe 都包含在它自己的 document 中。此 document 对象包含该 iframe 的全局范围。您无法访问全局范围之外的任何内容,因此 iframe 只能使用在 iframe 内部创建的变量。

关于javascript - 使用 Chrome 访问全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8658287/

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