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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.