How Do I Keep My Website From Being Viewed In a Frame?
Using Javascript to escape frames
By
Steve on
Thursday, January 11, 2007
Updated
Friday, April 22, 2016
Viewed
16,482 times. (
0 times today.)
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>