【发布时间】:2016-07-03 12:40:30
【问题描述】:
MainWindow 创建一个 JavaScript 对象,ChildWindow 需要利用该对象。
我的 MainWindow.html 现在看起来像这样
<html>
<body>
<script>
var varObject = {type:"Error", message:"Lots"};
</script>
<iframe class="child" src="ChildWindow.html"></iframe>
</body>
</html>
ChildWindow.html 看起来像这样
<html>
<body>
<script>
console.log(varObject.type); // goal is to log "Error"
</script>
</body>
</html>
ChildWindow 正在尝试使用在 MainWindow 中创建的对象,但它当然不能,因为我还不知道如何传递它。
我尝试在 Google 上搜索这个,但我发现的大多数解决方案都涉及将值作为字符串而不是变量传递。
【问题讨论】:
标签: javascript html iframe scope arguments