Break from frames based on parent url
I'm trying to help a friend of mine break his site out of some nasty footage: an example . This isn't usually a problem, but this particular site crosses some ethical boundaries by placing ads at the top of the page that does NOT pay my friend.
This is where it gets complicated, he would like his site to be in frames for certain sites like netvibes .
So, I tried something like this:
<!-- start break from getweb.info -->
<script type="text/javascript">
purl = parent.location.href;
//alert(purl);
if(purl.indexOf('getweb') > 0 && top.frames.length!=0)
{
top.location=self.document.location;
}
</script>
<!-- end break from getweb.info -->
However, since it has to be a conditional break, this doesn't work because firefox. (assuming others also have the same error, not yet tested) gives a message that the site in the frame is not allowed to receive the location.href property of the parent frame.
Is there a way for JavaScript to break out of a frame based on the parent location of the frame?
a source to share
You work under the same origin policy . You cannot see the location (or any other properties) of a frame with a different origin domain.
However, you can see your own document.referrer
. If you are created in a frame, then the referrer must be the URL of the containing frame.
if (window.self != window.top && document.referrer.indexOf('getweb') > 0 ) {
top.location.replace(window.location.pathname);
}
It is not bulletproof. For example, a framing site might use an intermediary (like netvibes). However, it can be annoying for them to stop building their site for friends.
a source to share