Connecting Tech Pros Worldwide Help | Site Map

What frame a page is in

  #1  
Old July 23rd, 2005, 08:50 PM
Andrew Poulos
Guest
 
Posts: n/a
How can a page know which frame in a frameset it is in?

Andrew Poulos
  #2  
Old July 23rd, 2005, 08:50 PM
Martin Honnen
Guest
 
Posts: n/a

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/
  #3  
Old July 23rd, 2005, 08:50 PM
VK
Guest
 
Posts: n/a

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

  #4  
Old July 23rd, 2005, 08:50 PM
Andrew Poulos
Guest
 
Posts: n/a

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

  #5  
Old July 23rd, 2005, 08:50 PM
Martin Honnen
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i know the frame my page is in? dik mus answers 8 November 18th, 2005 11:22 AM
Help with reloading frame page please Dynamo answers 1 July 23rd, 2005 10:01 PM
progress bar indicates the page is in downloading, but it is already finished alex answers 1 July 19th, 2005 09:58 AM