View Full Version : How do you tell if your site is inside of an iframe?
hotwheelharry
07-03-2009, 11:34 PM
I would like to know how to tell if my site is inside of an iframe, how many layers deep, and what the top level url is. Is this possible?
Thanks.
ckeyrouz
07-04-2009, 08:08 AM
Using java script you can do the following:
// this function returns the number of level deep
function getNbLayers()
{
var nbLevel = 0;
var obj = parent;
do
{
if(obj != null)
{
nbLevel ++;
obj = obj.parent;
}
}
while(obj != null)
return nbLevel
}
but if you want to know the url of the top frame, try this:
var zUrl = window.top.location.href
or
zUrl = window.top.location.pathname.
hotwheelharry
07-08-2009, 04:47 AM
thanks! answered all my questions and is very easy!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.