HTML iframe和javascript

HTML iframe和javascript

问题描述:

我有两个iframe,每个iframe显示两个不同的html页面。两个html页面都引用一个包含全局变量的常见javascript文件。如果我在html页面加载期间在一帧中设置该全局变量的值。是否可以使用相同的全局变量访问另一个iframe html页面?为什么或为什么不呢?

I have two iframes and each iframe show two different html pages. Both html pages refer to a common javascript file which contains a global variable. If I set the value of that global variable in one frame during html page load. Will the value be accessible using the same global variable to another iframe html page? why or why not?

没有。 JavaScript的范围空间的顶级是页面级别。但是,您可以使用 window.parent

No. The top level of JavaScript's scope space is the page level. However, you can access another page's scope by using window.parent