I'm having issues accessing a frame that is part of a page loaded into a iframe. The frame is nested in multiple framesets.
My html looks like this:
<iframe name="sourceframe" src="siteindex.html">
#document <-- this appears in the dom tree. Not sure if it's relevant.
<html>
<head></head>
<frameset>
...other frames
<frameset>
<frame name="targetframe" src="sitesubpage.html">
...I want to access this frame and replace the contents with a different html page...
</frame>
</frameset>
</frameset>
</html>
</iframe>
I have read similar questions none of which have a solution that I can get to work.
Any suggestions would be greatly appreciated.
Nested frame setsFramesets may be nested to any level. In the following example, the outer FRAMESET divides the available space into three equal columns. The inner FRAMESET then divides the second area into two rows of unequal height.
Creating Frames To use frames on a page we use <frameset> tag instead of <body> tag. The <frameset> tag defines, how to divide the window into frames. The rows attribute of <frameset> tag defines horizontal frames and cols attribute defines vertical frames.
window.frames['sourceframe'].frames['targetframe'].location.href = 'new_html_page';
FF and Chrome have frames
collection only in window
, IE and Opera have it also in the document
. The above code works (tested), when you get your timing corrected.
Try to use some timeout before changing the the href
, or trigger the change from the #targetframe
. Also you can attach an onload
event listener to the iframe
, and trigger the change in it. One more, you can place the script creating the iframe
just before closing body
tag, then you can use window.onload
to change the page in the depths...
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