Connecting Tech Pros Worldwide Forums | Help | Site Map

What frame a page is in

Andrew Poulos
Guest
 
Posts: n/a
#1: Jul 23 '05
How can a page know which frame in a frameset it is in?

Andrew Poulos

Martin Honnen
Guest
 
Posts: n/a
#2: Jul 23 '05

re: What frame a page is in




Andrew Poulos wrote:
[color=blue]
> How can a page know which frame in a frameset it is in?[/color]

window.name
gives you the name of the window or frame thus whatever.html when loaded in
<frame name="frameName" src="whatever.html">
can check
if (window.name == 'frameName')
That obviously does not help with unnamed frames but then you would need
to walk the frames and compare each to window to find out which frame
you are in.


--

Martin Honnen
http://JavaScript.FAQTs.com/
VK
Guest
 
Posts: n/a
#3: Jul 23 '05

re: What frame a page is in


You did not say where your script is: in the frameset or in an inner
frame.
For inner frames could be:

function whereIAm() {
var tmp = null;
for (i=0;i<window.top.frames.length;i++) {
if (window.top.frames[i] === self) {
tmp = window.top.frames[i];
break;
}
}
return tmp;
}

If you are using nested framesets (I hope not :-), then you need to use
recursive calls checking if (window.top.frames[i].frames) != 0

Andrew Poulos
Guest
 
Posts: n/a
#4: Jul 23 '05

re: What frame a page is in


>> How can a page know which frame in a frameset it is in?[color=blue]
>
>
> window.name
> gives you the name of the window or frame thus whatever.html when loaded in
> <frame name="frameName" src="whatever.html">
> can check
> if (window.name == 'frameName')
> That obviously does not help with unnamed frames but then you would need
> to walk the frames and compare each to window to find out which frame
> you are in.[/color]

If the frames are unnamed and I do a comparison, say,
window.frames[1].location == self.location
that would "fail" if the same page was loaded into more than one frame.

So does that mean that in some situations the page can't know what frame
it's in?

Andrew Poulos

Martin Honnen
Guest
 
Posts: n/a
#5: Jul 23 '05

re: What frame a page is in




Andrew Poulos wrote:
[color=blue]
> If the frames are unnamed and I do a comparison, say,
> window.frames[1].location == self.location
> that would "fail" if the same page was loaded into more than one frame.[/color]

There is no need to compare the location, you should compare the objects
e.g.
parent.frames[1] == window

--

Martin Honnen
http://JavaScript.FAQTs.com/
Closed Thread