0

I need to run a function at the start of the pageload, but it just simply doesn't work. I have a parent HTML (called main) and three frames (childs frameA, frameB, frameC).

main.html:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <script type="text/javascript" src="js/main.js"></script>
    <title></title>
    </head>
    <frameset cols="40%,*">
    <frameset rows="55%,45%">
            <frame src="frameA.html" name="frameA" id="frameA" />
            <frame src="frameB.html" name="frameB" id="frameB" />
        </frameset>
            <frame src="frameC.html" name="frameC" id="frameC" />
    </frameset>
    </html>

FrameA, B, C:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <title>FrameA</title>
    </head>
    <body>
    <h1>FRAME A</h1>
    </body>
    </html>

And the main.js:

    function resetC() {
        var oFrame = document.getElementById('frameC');
        oFrame.document.write("Frame C reseted");
    }
    resetC();

I got sick of "oFrame is null". Why does that happen?

  • Sorry for the vagueness of this answer, but the last time I had to do something like that I couldn't write directly to the frame, but I had to functions within the frame to pass information back and forth. Here's an example of how to do this: http://stackoverflow.com/questions/251420/invoking-javascript-code-in-an-iframe-from-the-parent-page. So basically, you have to have a function in the iframe to call to do the writing. – Snowburnt Nov 10 '13 at 02:44

1 Answers1

0

Move the js script down below the frameset and it should work...

just before the closing tag...

I think it's happening because the document has loaded yet to where your js can see the frame element...

Nathan Prather
  • 2,098
  • 1
  • 18
  • 15