View Full Version : how to detect location of parent frameset from page?

02-21-2003, 09:20 AM
I have a site which is currently displaying within a frameset (cloaked forwarding of the domain by the domain registrar). For reasons which are too boring to go into, I need certain browsers to take the page out of the frameset to be viewed. (for testing, I'm using IE 5.1)

I'm doing well with my browser detect (using a great script I found at http://www.dithered.com/javascript/browser_detect/index.html.), but I can't seem to detect whether the page is being displayed within a "parent" window. I've tried the script:

if (window.parent.location.href == "http://www.skmotorsport.com")
{window.parent.location.href = "http://www.skperf.com";}

But it simply didn't work.

I wondered whether I wasn't getting the parent window object properly addressed, so I made a simple test script that would tell me the parent window's URL:

alert (window.parent.location.href);

This didn't work either in the frameset context. But it DID work when I right-clicked and opened the frame in a new window.

Bang! Up comes the alert message with the URL.

So then I wondered whether it was because the frame the page was inside was being created by the domain registrar, whether that affected the script. So I created a frameset within my same domain, with the page inside that I'm hoping to "free."

Voila! My alert script worked perfectly, displaying the URL of the page. (the redirect still doesn't, though)

Is this a security issue? You can ONLY reference the frameset's attributes from a page inside it when the page and frameset are within the same domain? (the question at hand)

Is there any other way to do this?

Mr J
02-22-2003, 03:54 PM
Not too sure about this but it could be something like:


if (top.location.href.indexOf("frameset.htm") == -1){
top.location.href = "frameset.htm"
top.location.href = "thispage.htm

02-24-2003, 09:54 PM
I heard from another forum (http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20524893.html) that you cannot access the properties of a page in another domain (for security reasons). This seems to be the case, as all my scripting ideas work perfectly if I create a frameset in the same domain (skperf.com), but none of them function at all when I'm trying to detect the frameset properties in the parent domain (skmotorsport.com).