complete path to top frame

Discussion in 'Javascript' started by Cactus, Nov 10, 2003.

  1. Cactus

    Cactus Guest

    Hi,

    I have a tree like structure build with javascrtip and loads of
    iframes. How can find the complete 'frame-path' to the frame that
    focused? I'm sure I can contruct something with hidden input field so
    I can do a loop till I'm at the top frame, but there might be a much
    simpler way.

    -------------------------------------------
    | Top
    | ----------------------------------------
    | | Frame1
    | | -------------------------------------
    | | | Frame2
    | | | ----------------------------------
    | | | | Frame3
    | | | | -------------------------------
    | | | | | Frame4
    | | | | | ----------------------------
    | | | | | | Frame5
    | | | | | |

    In other ways, how do I know that I'm in
    Top.Frame1.Frame2.Frame3.Frame4.Frame5 when the focus is on Frame5?

    Hope someone knows the answer, thanks in advance

    Le Cactus
     
    Cactus, Nov 10, 2003
    #1
    1. Advertising

  2. (Cactus) writes:

    > I have a tree like structure build with javascrtip and loads of
    > iframes. How can find the complete 'frame-path' to the frame that
    > focused? I'm sure I can contruct something with hidden input field so
    > I can do a loop till I'm at the top frame, but there might be a much
    > simpler way.


    I don't think so. The pages in the frames are independent of each
    other, they don't need to know where they are in the frame structure.

    I can't see what the hidden input fields should do.

    > In other ways, how do I know that I'm in
    > Top.Frame1.Frame2.Frame3.Frame4.Frame5 when the focus is on Frame5?


    How do you know that the focus is in frame 5? That is the hard part.

    You can probably do that with onfocus-handlers on the frame objects.

    Assuming that you have a reference to the focused frame, currentFrame,
    then you can use the parent property to find the surrounding frame:

    function findPath(currentFrame) {
    var path = "";
    while (currentFrame != top) {
    path = "."+currentFrame.name+path;
    currentFrame = currentFrame.parent;
    }
    return "top"+path;
    }

    Then you can put this in each frame:

    <script type="text/javascript">
    self.onfocus = function() {
    top.currentFramePath = top.findPath(self);
    }
    </script>

    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Nov 10, 2003
    #2
    1. Advertising

  3. Cactus

    Disco Guest

    Cactus wrote:
    > Hi,
    >
    > I have a tree like structure build with javascrtip and loads of
    > iframes. How can find the complete 'frame-path' to the frame that
    > focused? I'm sure I can contruct something with hidden input field so
    > I can do a loop till I'm at the top frame, but there might be a much
    > simpler way.
    >
    > -------------------------------------------
    >> Top
    >> ----------------------------------------
    >> | Frame1
    >> | -------------------------------------
    >> | | Frame2
    >> | | ----------------------------------
    >> | | | Frame3
    >> | | | -------------------------------
    >> | | | | Frame4
    >> | | | | ----------------------------
    >> | | | | | Frame5
    >> | | | | |

    >
    > In other ways, how do I know that I'm in
    > Top.Frame1.Frame2.Frame3.Frame4.Frame5 when the focus is on Frame5?
    >
    > Hope someone knows the answer, thanks in advance
    >
    > Le Cactus


    Maybe a different way to think of what you are trying to accomplish (I am
    not exactly sure) would be to ensure the uniqueness of the frame names.
    IE. Wouldnt you assume that Top.Frame1.Frame2.Frame3.Frame4.Frame5 will
    definatly be Frame5 just because of the unique name of the frame?

    I can not see why you would have something like Top.Frame1.Frame5....
    instead you would have smoething like Top.Frame1.Frame1.5 or do smoething
    like this....
    Top.F1.F1_1.F1_1_1.F1_1_1_1
    Top.F1.F1_2.F1_2_1.F1_2_1_1
    Top.F1.F1_2.F1_2_2.F1_2_2_1
    Top.F1.F1_2.F1_2_1.F1_2_2_2


    This may or may not be any use to you. It was not use to me!
     
    Disco, Nov 10, 2003
    #3
  4. Cactus

    Cactus Guest

    Lasse Reichstein Nielsen <> wrote in message news:<>...
    > (Cactus) writes:
    >
    > > I have a tree like structure build with javascrtip and loads of
    > > iframes. How can find the complete 'frame-path' to the frame that
    > > focused? I'm sure I can contruct something with hidden input field so
    > > I can do a loop till I'm at the top frame, but there might be a much
    > > simpler way.

    >
    > I don't think so. The pages in the frames are independent of each
    > other, they don't need to know where they are in the frame structure.

    Bummer.
    >
    > I can't see what the hidden input fields should do.


    My idea was to put a hidden input field in earch frame. On frameload I
    could fill the field with that field value of the parrent frame and
    the current frame name. That way I would always know (in a frame)
    where I am.
    By calling a function in a frame witch returns me to the top frame, I
    could then use that value (after transfering it to another hidden
    field on the top frame) from where it was called.

    > > In other ways, how do I know that I'm in
    > > Top.Frame1.Frame2.Frame3.Frame4.Frame5 when the focus is on Frame5?

    >
    > How do you know that the focus is in frame 5? That is the hard part.
    >
    > You can probably do that with onfocus-handlers on the frame objects.
    >
    > Assuming that you have a reference to the focused frame, currentFrame,
    > then you can use the parent property to find the surrounding frame:
    >
    > function findPath(currentFrame) {
    > var path = "";
    > while (currentFrame != top) {
    > path = "."+currentFrame.name+path;
    > currentFrame = currentFrame.parent;
    > }
    > return "top"+path;
    > }

    Hmmm, thanks. That might also be a way to go about it. Thanks.

    >
    > Then you can put this in each frame:
    >
    > <script type="text/javascript">
    > self.onfocus = function() {
    > top.currentFramePath = top.findPath(self);
    > }
    > </script>
    >
    > /L


    Thanks for the input.

    Cheers,
    Catci
     
    Cactus, Nov 11, 2003
    #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. Gunter Hansen
    Replies:
    12
    Views:
    24,341
  2. Frederic HOUDE
    Replies:
    4
    Views:
    621
    Frederic HOUDE
    Aug 31, 2004
  3. Cuthbert
    Replies:
    8
    Views:
    454
    Ancient_Hacker
    Sep 13, 2006
  4. AAaron123
    Replies:
    6
    Views:
    605
    AAaron123
    Nov 5, 2009
  5. find clausen

    window.opener.top.location.top.close ???

    find clausen, Oct 5, 2003, in forum: Javascript
    Replies:
    2
    Views:
    451
    find clausen
    Oct 5, 2003
Loading...

Share This Page