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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

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:


The Network for Technology Professionals

Search:

About Internet.com

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

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger