How to detect if my page is loaded in a frame?

I have found that some websites are opening my page in a frame (a little like google does when you use search images).

Checking to see if there is a frame name lets me know if this has happened, but I do not know how to then remove the frame so the visitor can see my site in all its glory.

<script language="JavaScript" type="text/JavaScript">
function FrameCheck() {
if (this.frame) {
//some code here
}
}
onload = FrameCheck
</script>


window.location = “” only changes the frame its loaded in, and does not change the URL in the browser or remove the adverts/junk from the site. Is it possible to do this?


if(top!=window){
  top.location="new_location";
}

or


if (top.frames.length!=0){
  top.location="new_location";
}

In js, top is always the top level window element. So, if the window where this script run is in a frame below the top window, this will redirect the browser to the location you want.

If top is a different domain (which it will be) you’ll get an ‘access denied’ error when reading it.
Try this:

<script type='text/javascript'>

try
{
  if ( top.document.domain != self.document.domain )
  ;
}
catch(e)
 {
   top.location.href = self.location.href;
 }

</script>

Thanks!

for some reason i thought ‘window’ would be the whole window. My mistake :slight_smile: