Forum Moderators: open

Message Too Old, No Replies

Get top window address from a frame

         

empirebattles

1:07 am on Jun 7, 2009 (gmt 0)

10+ Year Member



I have a page that is in a frame on my site (example.com).
I am looking for a way to detect if someone has put my page in a frame on their own site (NOT example.com).

I attempted some different ways by simulating this on 2 different sites i have. I tried getting top.location.href and all sorts of other detection methods, but for some reason, when the page is in a frame on another site, top.location.href ends the script and doesn't work, while it gets the proper data from my site, example.com.

Is there any other way to detect the top address?

and NO. I do NOT want a break out script. The point is keeping the page in a frame, only on a certain address.

daveVk

1:32 am on Jun 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, cross domain 'same origin' policy will prevent it.

Search for "cross domain iframe" and you may find a workaround for your case.

empirebattles

1:44 am on Jun 7, 2009 (gmt 0)

10+ Year Member



roar.... so i have no way of stoping people from putting my frames on their site :( darn

tedster

2:01 am on Jun 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may not need to have the browser detect what the undesired top address actually is. If this URL is always intended to be framed by another URL on your domain, then you can use different logic.

Your script only needs to detect that your domain is top, and it doesn't matter what the actual domain is if that's not the case. So you test with an "if" statement, and then use replace() to load the intended top URL if your intended URL is not top - and it doesn't matter what the top url is if it isn't your page.

empirebattles

2:49 am on Jun 7, 2009 (gmt 0)

10+ Year Member



what exactly would i use to compare my domain with the domain that is framing it? Everything i use results in an error...

daveVk

4:31 am on Jun 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The point is keeping the page in a frame, only on a certain address

Does that certain address have the same domain as the iframe ?

empirebattles

12:08 am on Jun 8, 2009 (gmt 0)

10+ Year Member



yes. The page that is framing the other has the same domain.

sort of like "example.com/page.html" is the page which has the frame, while "example.com/frame.html" is the page that is in the frame. I dont want people to be able to put "example.com/frame.html" in a frame on their own site

daveVk

2:09 am on Jun 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, use the fact that refering to top.location.href fails if not same origin.

try { var x = top.location.href; }
catch (error) { ... frame buster code here ... }

Also check x, in case browser settings changed.