Paul McFedries' Web Home


Deframing a Page

Freeing a Page That's Stuck Inside Someone Else's Frames

In frame circles, proper etiquette dictates that links to external sites should either take over the entire screen (TARGET="_top") or should be displayed in a separate browser window (TARGET="_blank"). Unfortunately, many framesters don't follow this etiquette and, instead, greedily display every link within their frames. Besides cursing their ancestry, what can you do to make sure that your page doesn't get jailed within someone else's frames? Toss a little JavaScript at them, of course.

Assuming your page is named "index.asp", insert the following JavaScript into your page between the </HEAD> and <BODY> tags:

<script language="JavaScript" type="text/javascript">
<!--

if (top != self) {
    top.location = self.location
}

//-->
</script>

The if() test compares top with self. If they're not the same, it means your page is inside another site's frameset. You correct that by setting top.location equal to the address of your page as given by self.location.

This technique assumes your site doesn't use frames. If you do use frames, then one of two things will happen:

  • If the other site linked to your frameset page, then all will be well because the script will cause your frameset to take over the browser window.

  • If the other site linked to one of your child pages (that is, a page that's supposed to be displayed in a frame), then the script will display that page outside of your frameset. To correct this, use my reframing script.
    Copyright © 1995-2008 Paul McFedries and Logophilia Limited