Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript访问框架的文档对象_Javascript_Html_Dom_Frame - Fatal编程技术网

使用JavaScript访问框架的文档对象

使用JavaScript访问框架的文档对象,javascript,html,dom,frame,Javascript,Html,Dom,Frame,我正在测试,我不确定我错过了什么 // 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"

我正在测试,我不确定我错过了什么

// 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(最新稳定版)中进行测试。

您可以使用

parent.frame.location.href = ...
其中frame是要更改的帧的名称/id

问候
Marc

获取框架内容的全面方法如下:

var theFrame = document.getElementsByTagName("frame")[0];
var theFrameDocument = theFrame.contentDocument || theFrame.contentWindow.document;
var button = theFrameDocument.getElementById("mybutton");
但是,可以使用
的名称获取其文档,如:

window.frames["frame_name"].document
如果HTML是:

<frame name="frame_name">...</frame>
。。。

您是在2013年实际使用框架,还是那些iFrame?document.getElementsByTagName(“框架”)[0]怎么样?contentDocument?
var frame=document.getElementsByTagName(“框架”)[0];var frame_doc=frame.contentWindow.document | | frame.contentDocument-然后使用
frame\u doc
作为框架的文档可能重复的