October 16, 2000 - More on Forcing Frames | WebReference

October 16, 2000 - More on Forcing Frames

Yehuda Shiran October 16, 2000
More on Forcing Frames
Tips: October 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

When dealing with frames, you may not like one of your lower-level frames to be displayed by itself, out of its frame context. The reasons for this preference vary. For example, your company logo may not be on each frame and thus you don't want someone to display any of your pages without your logo. Another reason may be that one frame includes navigation assistance, and without it your frame won't look or feel the same. The remedy is quite straightforward. You include the following script in each frame's HEAD section:

<SCRIPT LANGUAGE="JavaScript">
<!--
if (window == top) top.location.href = "001016f.html";
// -->
</SCRIPT>

The script first checks whether the current window is equal to top. If it is, the top FRAMESET file is assigned to top's address, overwriting the current lower-level frame. This link demonstrates this trick. The link points to a lower-level frame, but when you click it, the top-level FRAMESET is loaded instead. This frame, on the other hand, does not include the script above, and thus does not force the top-level FRAMESET when clicked.

Here is the code for the top-level FRAMESET, 001016f.html:

<HTML>
<HEAD>
<TITLE>Top Level FrameSet</TITLE>
</HEAD>
<FRAMESET COLS="200, *">
   <FRAME SRC="001016a.html" NAME="leftcolumn">
   <FRAMESET ROWS="100, *">
      <FRAME SRC="001016b.html"  NAME="toprow">
      <FRAME SRC="001016c.html" NAME="bottomrow">
   </FRAMESET>
</FRAMESET>
</HTML>

Here is the frame with the script above, 001016a.html:

<HTML>
<HEAD>
	<TITLE>Left Tall Frame</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
if (window == top) top.location.href = "001016f.html";
// -->
</SCRIPT>
</HEAD>
<BODY>
This is the left tall frame
</BODY>
</HTML>

Here is the right top frame, 001016b.html:

<HTML>
<HEAD>
	<TITLE>Right Top Frame</TITLE>
</HEAD>
<BODY>
This is the right top frame
</BODY>
</HTML>

And finally, here is the the right bottom frame, 001016c.html:

<HTML>
<HEAD>
	<TITLE>Right Bottom Frame</TITLE>
</HEAD>
<BODY>
This is the right bottom frame
</BODY>
</HTML>

Learn more about frames in Column 36, Frames and JavaScript, Part I, and in Column37, Frames and JavaScript, Part II.