Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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!

like image 200
Nick Avatar asked Mar 24 '10 17:03

Nick


People also ask

How do you access an element in a frame?

frames property returns an array of all frames inside the current window. A frame can then be accessed by using its index or by its name. var element = window. frames['frame1'].

How can a script in one frame access another frame in JavaScript?

To access a variable in one frame from javascript in another frame, you need a reference to the variable's containing window object. The window object has a property named "top", which is a reference to the top-level window object. This corresponds to the frameset window.

Does frameset use body tag?

A frameset tag is the collection of frames in the browser window. Creating Frames: Instead of using body tag, use frameset tag in HTML to use frames in web browser. But this Tag is deprecated in HTML 5. The frameset tag is used to define how to divide the browser.

Is frameset deprecated?

<frameset> Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.


2 Answers

You need to get the Document object for the frame.

window.frames[1].document.getElementById('someElementId') 
like image 59
morgancodes Avatar answered Oct 02 '22 07:10

morgancodes


<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; 
like image 21
Vinod Avatar answered Oct 02 '22 07:10

Vinod