Subscribe to Tutorial Feed

Flash and PHP Bible

The Flash and PHP Bible has been released! The book can be found on Amazon or wherever fine books are sold in your area.

The Flash and PHP Bible has a forum for quick support.

Scriptplayground » tutorials » js » Frame Busting

Frame Busting

A very easy way to ensure your site is not being displayed in a frame.

Here is the simple code used to ensure your site is not being displayed in a frame. This is good to use when you have people "scraping" your sites content by basically including your site in their code.

Simply place the code in the "head" of your page or you could even place it in an external javascript file to cut down on filesize.

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

That is all it takes to "bust" out of a frame and ensure your site is displayed on top.

Follow Scriptplayground on Twitter (@scriptplay)

Comments: Frame Busting

 kristoficus  Mon Nov 7, 2005 10:41 pm  
Nice and simple tut matt :)

Small amount of code and very usefull. Great!
 3 me's  Tue Nov 8, 2005 12:27 pm  
Nice, well known also but always handy. Any chance of putting examples of the code up so that people can see how it sould work and then they know if it's NOT working for them. ;)

Catch ya !
 mkeefe  Thu Nov 10, 2005 6:11 pm  
Good idea on the example idea, I know some of them have examples and I will be adding them to more of the articles.
 gangsta  Sun Jul 30, 2006 12:55 pm  
hell yes!
 Bipin 3~ Upadhyay  Tue Aug 14, 2007 3:50 am  
Not Really.
This will not work in IE if the attackers embeds "security=restricted" parameter to the frame or iframe.
Working Demo:
http://crypto.stanford.edu/framebust/
 l8r  Wed Nov 12, 2008 5:35 pm  
Read Jeremy's posting on October 21st, 2008 at 5:58 am:

http://ha.ckers.org/blog/20081007/clickjacking-details/#comment-87102

The stanford.edu/framebust stuff can be properly mitigated in this fashion.
Add a comment
The ability to add new comments has been disabled in this archived version.

Loading
Main | Tutorials | Articles