complete path to top frame

C

Cactus

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
 
L

Lasse Reichstein Nielsen

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
 
D

Disco

Cactus said:
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.

-------------------------------------------

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!
 
C

Cactus

Lasse Reichstein Nielsen said:
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.
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top