top.frames在firefox中不起作用

时间:2013-03-13 11:02:43

标签: javascript firefox

我在页面中使用了两个iframes 父页面有iframeid = grandparent , src = "child.html".

并且在child.html中我设置了一些变量,而且在child.html中有一个iframe

id = parent, src="grandchild.html"

从grandchild.html我使用JavaScript

访问child.html中的变量
var value = top.frames['grandparent']

它在chrome中工作正常,但在firefox中无法使用值变量,我无法访问child.html的变量

请帮助

1 个答案:

答案 0 :(得分:2)

Firefox的行为是规范要求的行为。请参阅http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#dom-window-nameditem-filter以及在http://www.whatwg.org/specs/web-apps/current-work/multipage/the-iframe-element.html#the-iframe-element

浏览上下文名称的规则

WebKit有一个已知错误(请参阅https://bugs.webkit.org/show_bug.cgi?id=11388),它将iframe的id转换为里面窗口的名称。

对于您的情况,您只想在相关的iframe上使用name="grandparent"