Click to See Complete Forum and Search --> : Is page in a frame


Webskater
07-11-2003, 08:28 AM
I have a site with a simple frame layout - top, main and bottom. There are also numerous pop-up windows. Is there an easy way to find out if a page is within the Main frame or is within its own window. So...

I am a page called ShowStock.asp
Am I in a frame called Main or am I somewhere else?

Thanks for any help. At the moment I have a variable being sent in a thousand different directions to try and keep track of where the page is.

Khalid Ali
07-11-2003, 09:05 AM
from within the page you can do this

put the following code in the head section of the page

<script type="text/javascript">
<!--
var thisparent = this.parent;
var thisframe = this;
//see if this page has aprent frame
if(thisparent.name!=null && thisparent.name!=""){
alert("This page is opened in a frameset and the current parent frames name is = "+thisparent.name+
"\nAnd this frames name = "+thisframe.name);
}else{
alert("This page is not in a frameset"+
"\nAnd hence no frame name = ");
}
//-->
</script>

Webskater
07-11-2003, 09:20 AM
Thanks Khalid. That does the job perfectly. Do you know if there is a way to find out on the server if the page is being opened in a frame or in a new window? I want to hide some things and show others depending on whether the page is in its own window or in the Main frame. Thanks to your code I can do it client side but I wonder if it can be done on the server.

Charles
07-11-2003, 09:26 AM
Khalid's method will work as long as the frames all have names. For something that will work either way use if (self.location == top.location).

Khalid Ali
07-11-2003, 09:43 AM
You are welcome webskater .
Oh BTW Charles..
try reading the question before getting blinded by your urge to (always) undermine my effort to help people.


I am a page called ShowStock.asp
Am I in a frame called Main or am I somewhere else?


I am all ears and eyes to find out that how are you going to find out the name in the solution you suggested above?....

Charles
07-11-2003, 09:49 AM
Yes, I was distracted by your response that has hidden deep within it the answer to the question. But it is simply a fact that you have overlooked that not all frames have names and strictly speaking that which you have posted will not always work.

Khalid Ali
07-11-2003, 09:55 AM
Originally posted by Charles
But it is simply a fact that you have overlooked that not all frames have names

This is has gotten ridiculously sad....
How in the heck you know what I was thinking....this is absurd...

Charles
07-11-2003, 09:58 AM
if(thisparent.name!=null && thisparent.name!=""){
alert("This page is opened in a frameset and the current parent frames name is = "+thisparent.name+
"\nAnd this frames name = "+thisframe.name);
}else{
alert("This page is not in a frameset"+
"\nAnd hence no frame name = "); I suppose that you could have been intentionally trying to mislead but I choose to think that you would not do that.