spacer
Yehuda Shiran December 4, 1999
Forcing Frames
Tips: December 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

If you've designing a frame-based Web page, you may want to make sure the child documents aren't viewed in the main window. We can use JavaScript to load the frameset document if one of the child documents is loaded in the browser window. The following expression can be used to determine if the current page isn't inside a frame:

if (self == top) {
  // current document is in the top-level window
}

If you're not familiar with the keywords self and top, be sure to read Window References (November 7, 1999). Once we have determined that we need to launch the entire frameset, we load the frameset document:

top.location.replace("parent.html");

The location.replace() method loads the frameset document without leaving the current document in the browser's history list. Our final script needs to be embedded in the document (preferably in the HEAD portion):

<SCRIPT LANGUAGE="JavaScript">
<!--

if (self == top) {
  if (parseInt(navigator.appVersion) == 2) // is the browser Navigator 2?
    location.href = "parent.html" // for Netscape Navigator 2
  else
    location.replace("parent.html");
}

// -->
</SCRIPT>

If you put this script in the HEAD portion of the document, the frameset document is called before the current document loads, so the user doesn't need to wait. Refer to Column 36, Frames and JavaScript, Part I, for a more powerful solution, and several other frame-related tips.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business