Solution to find a frame by name in the frame hierarchy

Discussion in 'Javascript' started by Daniel Frede, Jan 27, 2005.

  1. Daniel Frede

    Daniel Frede Guest

    <script>try {
    var frame1;
    frame1=find('myFrameNameToFindInHierarchy',getFrame('myTopFrameName', window));
    //debugger;
    alert(frame1.name);
    //Do something with the frame
    frame1.document.location.reload;

    }catch (e) {};


    // Get frame by framename (recurse down)
    function find(what,current) {
    var ret;
    for (var i=0;i<current.frames.length;i++) {
    if (current.frames.name == what){
    return current.frames;
    }
    ret = find(what,current.frames);
    }
    return ret
    }


    // Get top frame by name (recurse up)
    function getFrame(TopFrameName, currentWindow){
    if (currentWindow.name == TopFrameName){
    return currentWindow;
    }
    if (currentWindow.name == currentWindow.parent.name){
    return getFrame(TopFrameName, currentWindow.opener);
    } return getFrame(TopFrameName, currentWindow.parent);
    }

    </script>
    Daniel Frede, Jan 27, 2005
    #1
    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. Jeffrey Barish

    Name conflict in class hierarchy

    Jeffrey Barish, May 20, 2006, in forum: Python
    Replies:
    8
    Views:
    253
    bruno at modulix
    May 23, 2006
  2. Riyaz
    Replies:
    5
    Views:
    1,044
  3. Georgios Zakitraxis

    FRames, how to retrieve from frame 1 name of frame 2

    Georgios Zakitraxis, Feb 10, 2005, in forum: Javascript
    Replies:
    1
    Views:
    89
    kaeli
    Feb 10, 2005
  4. Mel

    frame hierarchy question...

    Mel, Mar 22, 2005, in forum: Javascript
    Replies:
    2
    Views:
    85
    Mick White
    Mar 22, 2005
  5. Replies:
    6
    Views:
    314
Loading...

Share This Page