Cambia Research - Supporting the Microsoft .NET Developer Community Supporting the Microsoft .NET Developer Community  

     | Home  | Articles  | Categories  | Coders  | Search  | Submit  | Contact Us    
When you start off by telling those who disagree with you that they are not merely in error but in sin, how much of a dialogue do you expect? --Thomas Sowell

Share Your Knowledge! -- Create and submit your articles the easy way with WebWriter.

Updated:02:16 AM CT Jan 11, 2007
Posted:01:48 AM CT Jan 11, 2007

How Do I Keep My Website From Being Viewed In a Frame?

Using Javascript to escape frames

Author: Steve Lautenschlager

BeginnerJavascriptBrowsersClient SideWeb

 Summary

Certain websites, such as search engines or email providers, will forward to new web pages inside a frame so they can continue to show their own banner at the top of the page. This, in my humble opinion, is bad form--similar to popups.

You can actually force a browser to load your page and drop the frame using a little bit of javascript. Once again, I don't recommend this because it's generally a bad idea to mess with a person's browser (maybe they like the frame), but I have had occassion to use it when the frames caused problems for web page.

Example: How to escape a frame and load your page in the browser

<HTML> 
   <HEAD>   
      <SCRIPT language="javascript">
      <!--
         if (top != self) 
            top.location = location;
      //-->
      </SCRIPT>
   </HEAD>
   <BODY>
      Test page.
   </BODY>
</HTML>

Add New Comment
Nice, but what happens if user wants to view this page inside a frame?
Peto26 Oct 07, 2:27Reply 
How Do I Keep My Website From Being Viewed In a Frame?
Charly28 Dec 07, 15:43Reply 
re: How Do I Keep My Website From Being Viewed In a Frame?
andrew09 Aug 08, 10:53Reply 
CR Comments by Cambia Research
advertisement
 
Steve Lautenschlager (steve)
Steve is the founder and creator of Cambia Research. Developing and maintaining the site combines his passions for technology, writing and education.
Steve holds a Ph.D. in particle physics from Duke University, has worked at CERN, the European center for particle physics (where the web was born) and in Microsoft's web division with microsoft.com, msnbc.com and other web properties. Steve is a web consultant specializing in Microsoft.NET technologies. Read more here.


 
Copyright © Cambia Research 2002-2007. All Rights Reserved. steve [ at ] cambiaresearch.com