December 4, 1999 - Forcing Frames
December 4, 1999 Forcing Frames Tips: December 1999
Yehuda Shiran, Ph.D.
|
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.