html tutorials web design help css tutorials free web graphics diy search engine optimization

Break Out of Frames

Sometimes our sites get trapped inside another sites frames. That's not considered good Netiquette in most circles, but I have 2 scripts you can use to automatically have your site break free from someone else's frames. A third bit of code allows the user to click a link to break out of frames. It's the most reliable of the three because it doesn't rely on JavaScript, but most users do have JavaScript capable browsers so any of these methods are good.

Method 1

Here's the first automatic script:
<script type="text/JavaScript">

if (top.location != location) top.location.href = location.href; </script>

Method 2

Here's the second automatic script:
<script type="text/JavaScript">

setTimeout ("changePage()", 3000); function changePage() {if (self.parent.frames.length != 0) self.parent.location="";} </script>

Method 3

By placing the following link on your page a user can click it to break out of another site's frames. Here's the code:
Trapped in a Frame? <a href=""
target="_top">Break Out Now</a>  
Note: Place the code for either of the first two methods in the HEAD section of your page. Place the link code in the third method where you want the link to appear on your page.

You may have been framed, but you just got a 'Get Out Of Jail Free' card.

Back | Web Design Tutorials Index

Ezine for Webmasters

Bookmark and Share

Almost a Newsletter

Changing list hosts. Will post a new subscribe form shortly.

Did you know...

The member's site has about 100 standards compliant HTML and CSS tutorials, 31 handy reference charts, reprintable content, web graphics, exclusive fonts, free software, free ebooks and more? All this for less than 9 cents a day! [ Details ]
See my fancy bottom! :)