Controlling frames with javascript

Discussion in 'Javascript' started by Big Daddy, Apr 22, 2009.

  1. Big Daddy

    Big Daddy Guest

    I have a simple page with 2 frames and want to be able to change the
    source for the frames with javascript. See this source:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="JavaScript">
    window.frames[0].location='something';
    window.frames[1].location='whatever';
    </SCRIPT>
    </HEAD>
    <frameset ID="aFrameset" rows='103px,100%'>
    <frame noresize='0' scrolling='no' name='top' id='top'>
    <frame noresize='0' scrolling='yes' name='bottom' id='bottom'>
    </frameset>
    </HTML>

    The code causes an error because the frames array doesn't have any
    frames in it. I try to access the frames using their name or ID
    instead (e.g. getElementById), but that doesn't work either. I have
    tried to move the javascript to be after the frames declaration, but
    it doesn't get called at all. I am using IE 7.

    Any ideas how I can do this? thanks in advance,
    John
    Big Daddy, Apr 22, 2009
    #1
    1. Advertising

  2. Big Daddy

    Tim Streater Guest

    In article
    <>,
    Big Daddy <> wrote:

    > I have a simple page with 2 frames and want to be able to change the
    > source for the frames with javascript. See this source:
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > <HTML>
    > <HEAD>
    > <SCRIPT LANGUAGE="JavaScript">
    > window.frames[0].location='something';
    > window.frames[1].location='whatever';
    > </SCRIPT>
    > </HEAD>
    > <frameset ID="aFrameset" rows='103px,100%'>
    > <frame noresize='0' scrolling='no' name='top' id='top'>
    > <frame noresize='0' scrolling='yes' name='bottom' id='bottom'>
    > </frameset>
    > </HTML>
    >
    > The code causes an error because the frames array doesn't have any
    > frames in it. I try to access the frames using their name or ID
    > instead (e.g. getElementById), but that doesn't work either. I have
    > tried to move the javascript to be after the frames declaration, but
    > it doesn't get called at all. I am using IE 7.
    >
    > Any ideas how I can do this? thanks in advance,
    > John


    Probably when the JS executes, the frames don't exist yet. You want to
    put:

    onload="initialise();"

    or whatever in your <frameset> declaration, and then put the code in
    your initialise() function.

    --
    Tim

    "That excessive bail ought not to be required, nor excessive fines imposed,
    nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
    Tim Streater, Apr 22, 2009
    #2
    1. Advertising

  3. Big Daddy wrote:
    > I have a simple page with 2 frames and want to be able to change the
    > source for the frames with javascript. See this source:
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > <HTML>
    > <HEAD>
    > <SCRIPT LANGUAGE="JavaScript">
    > window.frames[0].location='something';
    > window.frames[1].location='whatever';


    You need to wait for the document to load e.g.
    window.onload = function()
    {
    window.frames[0].location.href = 'doc1.html';
    window.frames[1].location.href = 'doc2.html';
    };

    > </SCRIPT>




    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
    Martin Honnen, Apr 22, 2009
    #3
  4. Big Daddy

    Big Daddy Guest

    Thanks to both of you that responded. It worked!
    Big Daddy, Apr 22, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. headware

    controlling redirection within frames

    headware, Aug 5, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    329
    headware
    Aug 5, 2003
  2. Powerslave2112

    From Frames to no frames?

    Powerslave2112, Jan 20, 2004, in forum: HTML
    Replies:
    2
    Views:
    576
    brucie
    Jan 20, 2004
  3. Philip
    Replies:
    3
    Views:
    954
    Karl Groves
    Jun 28, 2004
  4. Ale

    Frames or not Frames...

    Ale, Aug 3, 2005, in forum: HTML
    Replies:
    17
    Views:
    949
    Adrienne
    Aug 5, 2005
  5. Jenn
    Replies:
    2
    Views:
    146
Loading...

Share This Page