Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript, accessing nested frames in framesets from a iFrame

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.

like image 375
ThunderHorse Avatar asked Jul 10 '13 22:07

ThunderHorse


People also ask

Can frames be nested?

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.

How do you frame in Javascript?

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.


1 Answers

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

like image 69
Teemu Avatar answered Sep 19 '22 20:09

Teemu