JavaScript Frame Buster

Jun 9, 07:19 PM

There are a number of reasons you would want to prevent your page or site’s contents to be contained within a frame or iframe:

  • you might have problems with someone using your content on their site
  • security concerns
  • controlling your site’s functionality and/or presentation

This small bit of code somewhere within your HTML documents will detect whether or not it’s been loaded into a frame and, if so, will “bust” out of the frame by loading the page in the main window.

<script type="text/javascript">
//<![CDATA[
if (top != self) {
	top.location.href = self.location.href; 
} 
// ]]>
</script>

This is not a security panacea, and there are ways around it. But it is a quick and easy way of preventing a third party from doing something silly with your site.

Bookmark and Share
 

Comment

|

Valid XHTML 1.1 Valid CSS
             © 2008, garvin