Prevent your website being displayed inside IFRAME

Advertisement

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.

Popularity: 4% [?]

Enter your email address and get free tutorials, tips and tricks of PHP, Ajax, JavaScript and CSS directly delivered to you email inbox:

Related Posts

» Prevent Directory Listing using .htaccess
» Hide actual url in address-bar using iframe
» Change default directory page using .htaccess
» Prevent form post request from another domain in PHP

7 Comments on “Prevent your website being displayed inside IFRAME”

  • Arwind Prasad wrote on 24 June, 2008, 13:54

    I was looking for same solution.
    Thanks Alot……

  • subesh wrote on 25 June, 2008, 11:50

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

  • Roshan wrote on 25 June, 2008, 16:33

    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…

  • arty wrote on 2 July, 2008, 19:22

    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 :)

  • Sanjay Kumar wrote on 20 October, 2009, 18:30

    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.

  • wah umm wrote on 4 November, 2009, 8:09

    arty, could you specify the new way

Trackbacks

  1. pligg.com

Write a Comment