Nick
Nick

Reputation: 19664

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

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!

Upvotes: 27

Views: 55712

Answers (3)

Vinod
Vinod

Reputation: 533

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

Upvotes: 11

Praveen_07
Praveen_07

Reputation: 190

You can try using framename as well

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

Upvotes: 9

morgancodes
morgancodes

Reputation: 25265

You need to get the Document object for the frame.

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

Upvotes: 32

Related Questions