在iframe中定义top
define top in iframe
我有一个"弗兰肯斯坦"代码,如下所示:
<body>
<iframe src="ThirdPartyPage">
<... id="foo">
<iframe>
...
top.document.getElementById(foo)
...
</iframe>
</iframe>
</body>
有没有办法对javascript说顶部不是我的代码,而是ThirdPartyPage?
编辑:这里的问题不在于如何获得"foo"。这里的问题是,第三方页面正在字符串中从顶部获取"foo",但现在有了新的iframe,顶部就不再是第三方页了。
//To get the parent node i.e. ThirdPartyPage
document.getElementById("yourFrameId").parentNode
//Also you could get the elements within the ThirdPartyPage as follows (returns an array of elements)
document.getElementById("yourFrameId").parentNode.getElementsByTagName("tagName")
您不能重写top
,也不能使用getElementById(foo)
从iframe
访问任何DOM元素
您要找的是window.parent,而不是window.top.
相关文章:
- jQuery控制台错误:无法读取属性'top'的未定义
- 无法仅在活动服务器上读取未定义错误的属性“top”
- 正在尝试滚动页面:未捕获类型错误:无法读取属性'top'的未定义
- 未捕获的类型错误:无法读取属性'top'的未定义
- 重定义对最顶层窗口的引用 (window.top)
- 未捕获的类型错误:无法读取未定义的属性“top”
- JavaScript 运行时错误:无法获取未定义或空引用的属性“top”
- 无法读取未定义的链接 href 的属性“top”
- 未捕获的类型错误:无法读取未定义错误的属性“top”
- 偏移 JavaScript 滚动:无法读取未定义错误的属性“top”
- TypeError:无法读取属性'top'的未定义
- 无法读取属性'top'未定义的Jquery/javascript
- 在iframe中定义top
- 未捕获的类型错误:无法读取属性'top'的未定义(popupWindow.top.close();)
- 控制台错误:未捕获类型错误:无法读取属性'top'的未定义
- 未捕获的TypeError: Cannot read property 'top'的定义
- 不能读取property 'top'未定义的Ruby on Rails项目
- JavaScript中的Top或parent在使用FireFox或Opera的SharePoint 2010中未定义
- 未捕获的TypeError: Cannot read property 'top'的定义
- Drupal主题js错误-无法读取属性'top'的定义