Jump to content

[SOLVED] Stopping a site from iframing to me


Exoon

Recommended Posts

Hello,

 

I was wondering if its possible to check if the site has been loaded in an iframe and if it has then load it up to the full page automatically.

 

As i have a script that is counting hits in from a website like a topsite and want to stop people cheating it.

 

Thanks in advance.

I had found this somewhere and have modified it, wish I could credit the original source :(

 

<script language="javascript">
// DO I FEEL AN IFRAME??
try
{
    // Alright...what is the parent window url?
    var parent = window.parent.location;
    var str = new String(parent);
}
catch (e)  //CHECKING - IF IT IS IN AN IFRAME SHOW ERROR PAGE
{
    window.location = 'errorpage.html'; // CREATE AN ERROR PAGE AND PUT IT IN HERE
}
</script> 
<noscript>Your browser is not javascript enabled or it has been disabled.  Javascript is required to see this page.</noscript>

 

Hope this helps!

Here this will just simplify it if the visitors browser has javascript enabled:

 

<script type="text/javascript">
if (top.frames.length!=0) {
    if (window.location.href.replace)
        top.location.replace(self.location.href);
    else
        top.location.href=self.document.href;
}
</script>
<noscript>Your browser is not javascript enabled or it has been disabled.  Javascript is required to see this page.</noscript>

 

If a frame is detected it will remove it and place your site in the parent window.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.