What frame a page is in

M

Martin Honnen

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

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.
 
V

VK

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 === self) {
tmp = window.top.frames;
break;
}
}
return tmp;
}

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

Andrew Poulos

How can a page know which frame in a frameset it is in?
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.

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
 
M

Martin Honnen

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

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

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top