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;

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  Tue Nov 8, 2005 3:41 am  
Nice and simple tut matt :)

Small amount of code and very usefull. Great!
 3 me's  Tue Nov 8, 2005 5: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 11: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 4:55 pm  
hell yes!
 Bipin 3~ Upadhyay  Tue Aug 14, 2007 7:50 am  
Not Really.
This will not work in IE if the attackers embeds "security=restricted" parameter to the frame or iframe.
Working Demo:
 l8r  Wed Nov 12, 2008 10:35 pm  
Read Jeremy's posting on October 21st, 2008 at 5:58 am:

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

Main | Tutorials | Articles