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!
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'].
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.
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.
<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.
You need to get the Document object for the frame.
window.frames[1].document.getElementById('someElementId')
<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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With