Connecting Tech Pros Worldwide Help | Site Map

What frame a page is in

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 07:50 PM
Andrew Poulos
Guest
 
Posts: n/a
Default What frame a page is in

How can a page know which frame in a frameset it is in?

Andrew Poulos

  #2  
Old July 23rd, 2005, 07:50 PM
Martin Honnen
Guest
 
Posts: n/a
Default 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, 07:50 PM
VK
Guest
 
Posts: n/a
Default 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, 07:50 PM
Andrew Poulos
Guest
 
Posts: n/a
Default 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, 07:50 PM
Martin Honnen
Guest
 
Posts: n/a
Default 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/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.