【发布时间】:2013-02-03 09:06:13
【问题描述】:
我正在this page 上进行测试,但我不确定我错过了什么。
// Two frames on the page
> document.getElementsByTagName("frame").length
2
// Same domain, so no security restrictions
> document.getElementsByTagName("frame")[0].src
"http://www.quackit.com/html/templates/frames/menu_1.html"
> window.location.href
"http://www.quackit.com/html/templates/frames/frames_example_1.html"
// Can't access the document
> document.getElementsByTagName("frame")[0].document
undefined
看起来这应该可行,那么有什么问题吗?它需要在 IE8 中运行,但我也在 Chrome 中进行测试(最新稳定版)。
【问题讨论】:
-
你是在 2013 年实际使用框架,还是那些 iFrame?
-
document.getElementsByTagName("frame")[0].contentDocument呢? -
var frame = document.getElementsByTagName("frame")[0]; var frame_doc = frame.contentWindow.document || frame.contentDocument;- 然后使用frame_doc作为框架的文档
标签: javascript html dom frame