如何使用 JavaScript 从框架集框架中获取元素?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2509934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:41:08  来源:igfitidea点击:

How can I get an element from within a frameset frame using JavaScript?

javascriptframesframeset

提问by Nick

I need to access and element from within a frameset frame. For example if I have the following markup:

我需要从框架集框架内访问和元素。例如,如果我有以下标记:

<frameset rows="33%,33%,*">
  <frame src="frame1.html"/>
  <frame src="frame2.html"/>
  <frame src="frame3.html"/>
</frameset>

How can I get some element from one of the child frames? I have tried this:

如何从其中一个子框架中获取一些元素?我试过这个:

window.frames[1].getElementById('someElementId')

This results in a type error :

这会导致类型错误:

getElementById() is not a function.

getElementById() 不是函数。

Can someone assist?

有人可以帮忙吗?

Thanks!

谢谢!

回答by morgancodes

You need to get the Document object for the frame.

您需要获取框架的 Document 对象。

window.frames[1].document.getElementById('someElementId')

回答by Vinod

<frameset rows="33%,33%,*">
<frame id="demo" src="frame1.html"/>
<frame src="frame2.html"/>
<frame src="frame3.html"/>
</frameset>

Answer:

回答:

document.getElementById("demo").contentDocument.documentElement.innerHTML;

回答by Praveen_07

You can try using framename as well

您也可以尝试使用 framename

window.frames['frame_name'].document.getElementsByName('element_name');