Measuring programming progress by lines of code is like measuring aircraft building progress by weight. --Bill Gates
Welcome to my blog and project site for Microsoft.NET development.

I've been a full time .NET developer for ten years, but I didn't start my professional life as a programmer ... more
Share/Print this page:

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

Using Javascript to escape frames

By steve on January 11, 2007.
Updated on January 22, 2012.
Viewed 6,715 times (0 times today).
Article TypesLanguagesSoftware DevelopmentTechnologies
SnippetJavascriptClient sideWeb Browsers

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>
Back to Top

User Comments (3)

Posted 2007 Oct 26 02:27 AM. reply
How can I view a page with this script inside a frame? is it impossible?

I think that webs shouldn't take this decission, if you want to see a page out of frames you can use "open link in new window".

I'm looking for the way to keep webs with this script inside a frame, and it's not to show a banner.

Thanks!

Peto
Posted 2007 Dec 28 15:43 PM. reply
Is there a solution without scripting?

Charly
Replied 2008 Aug 09 10:53 AM by andrew. reply
as yet, no. However, if the W3C says so, there may be in future.
Post Your Comment
  You may post without logging in or login here.
Display Name: Required.
Email: Required. Will not be shown. Used for identicon.
Comment:
Allowed tags: <quote></quote>, <code></code>, <b></b>, <i></i>, <u></u>, <red></red>
 
   Please type text as shown in the image at left.