Prevent your website being displayed inside IFRAME

Sites like Google Image search and goodphptutorials.com displays the website under the IFRAME and I don’t think you guyz want your site to be displayed it under the IFRAME. If you want to protect your site to be displayed under the IFRAME then here is the tips for you.

 

JavaScript Code Prevent web page being displayed inside iframe

Place the following piece of code in JavaScript to those pages which you want to prevent being displayed inside the IFRAME.

<script type="text/javascript">
<!--
if (top.location.href != self.location.href)
  top.location.href = self.location.href;
//-->
</script>

The above code is simple and straightforward. First of all, it is checked that if url of the top frame is different to the URL containing the JavaScript code, if they are different then the website comes out of the IFRAME and gets displayed in the browser. This is how we can prevent your web page being displayed inside IFRAME but note that javascript must be enabled otherwise the code won’t take any action.

9 thoughts on “Prevent your website being displayed inside IFRAME

  1. I was looking for same solution.
    Thanks Alot……

  2. What If javascript is off…?. Can’t we do it from the doctype of the document……defining it strict…rather than transitional or loose

  3. subesh….if javascript is turned of then noone can help you in that sitaution..

    And Doctype can’t handle such scenario, doctype is a standard for how presentation is going to be handled by browser (basically css) and is a standard of using valid tags according to DTD specifications in the document…

  4. This way is oldschool but it still works … the good old frame braker.
    By the way this is not only for iframes … i would say it works for frames in general :)

  5. My Self Sanjay Kumar i am operating http://www.moneyinhands.com Recently i found IFrame Element on website. This Element automatically add on my website. i don’t know about this and in future please tell me details about how i can protect my website http://www.moneyinhands.com against any element or malware. Please also suggest me any software or script who can help me to protect my web pages against element and malware. I would also interested to know about how i can re appears my website on Google.com safely.

  6. wah umm

    arty, could you specify the new way

  7. hi, can you please tell me how to place google ads in right corner vertical (skyscrapper ones)of php , i mean what is the script to write ? is there any help ? please

  8. hey this worked 😀

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>