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

我怕爱的太早我们不能终老 提交于 2019-11-27 01:48:43

问题


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.

Can someone assist?

Thanks!


回答1:


You need to get the Document object for the frame.

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



回答2:


<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;



回答3:


You can try using framename as well

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


来源:https://stackoverflow.com/questions/2509934/how-can-i-get-an-element-from-within-a-frameset-frame-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!