Menu

Advanced Frames

This tutorial looks at some of the useful HTML tags available, and discusses the behavior of each.

The frameset tag

<frameset cols="x,x">
<frameset rows="x,x">

Each occurrence of the <frameset> tag must specify either columns (cols) or rows to be displayed. A <frameset> tag cannot contain BOTH cols AND rows – this effect is achieved by nesting frameset tags.

Columns or rows can be specified in either pixel or percentage value: <frameset cols="300,*"> or <frameset rows="25%,50%,25%">, and can contain as many columns or rows as you wish.

Each comma separated value (“X,”) represents a <frame src=""> which must be displayed. Therefore <frameset rows="25%,*,100"> would represent a window framed into 3 areas, 25% on top, 100 pixels high on the bottom.

Since we cannot know the height of the browser, we cannot determine the value of the middle frame – the * tells the browser to expand this frame to use the rest of the window.

Other <frameset> options:

<frameset frameborder="yes|no" border="0" framespacing="0">

These 3 frameborder controls should be used only to turn borders OFF.

If you want to leave the borders ON, don’t use anything. Browser manufacturers have dabbled with such controls as framespacing and bordercolor, but these should never be used unless your site is on a closed intranet. They are not well supported and your results can vary widely.

The frame tag

<frame src="file.url" name="name">

The <frame> tag is required for each “X,” row or column specified in the <frameset> tag. Each <frame> will require an initial page src="" to display, and a unique name="FrameName" to target with hyperlinks from other framed pages.

Other <frame> options:

  • scrolling="yes|no|auto" – add this to your <frame> tag to control the scrollbars for that frame. The default scrolling behavior for any unspecified frame is auto, which is to say: “Only display scrollbars IF the content runs outside the display area.”
  • marginheight="15" marginwidth="15" – you can control the margins for each frame with these options. The default value in most browsers is roughly 15 pixels.
  • noresize – IF you have frame borders visible, this option will “lock” them in place, and remove the user’s ability to resize the framed areas.

Closing the frameset

</frameset>

Believe it or not, this tag causes plenty of problems for those who forget it. It is required to close each instance of the <frameset> tag.

The noframes tag

<noframes></noframes>

It is very important that your <frameset> documents contain <noframes> content. You can insert custom content strictly for older browsers, but it is important that you at LEAST include a link to your main menu page.

A more complex example

Now that we’ve learned the tags, let’s create a more complex example:

+---------------------------------------------------+
|                 index.html (_top)                 |
| +------------+----------------------------------+ |
| | menu.html  | main.html (Main)                 | |
| | (Menu)     |                                  | |
| |            | Stuff, stuff, stuff              | |
| | - Link     | stuff, stuff, stuff              | |
| | - Link     +----------------------------------+ |
| | - Link     | nested.html (Nest)               | |
| | - Link     | +--------------+---------------+ | |
| |            | | sub-a.html   | sub-b.html    | | |
| |            | | (subA)       | (subB)        | | |
| |            | +--------------+---------------+ | |
| +------------+----------------------------------+ |
+---------------------------------------------------+

In this example, we have four src="" documents, and 4 named frames to target. We have nested our frameset twice, to combine rows and columns – once with tag nesting, and once with document nesting:

<frameset cols="30%,*">
    <frame src="menu.html" name="Menu">
    <frameset rows="60%,*">
        <frame src="main.html" name="Main">
        <frame src="nested.html" name="Nest">
    </frameset>
</frameset>

Now let’s examine each tag individually:

  • <frameset cols="30%,*"> – this tag defines 2 columns, one for the menu at 30%, and another for *, or the remaining 70% of the screen area.
  • <frame src="menu.html" name="Menu"> – for the first column, display the contents of menu.html, and give this frame the name “Menu”.
  • <frameset rows="60%,*"> – here we are defining a NEW frameset with 2 rows, which will display in the second column created by the frameset above.
  • <frame src="main.html" name="Main"> – for the top row of the second column, we insert our main page.
  • <frame src="nested.html" name="Nest"> – for the bottom row of the second column, we will include a new <frameset> document. As we will see, this will create yet 2 more columns, to display in the bottom row.
  • </frameset></frameset> – be sure to close each <frameset>.

nested.html example

The source of nested.html is simple enough:

<frameset cols="50%,50%" frameborder="no" border="0" framespacing="0">
    <frame src="sub-a.html" name="subA">
    <frame src="sub-b.html" name="subB">
</frameset>

Changing more than one frame

Our final discussion involves dynamically changing the contents of more than one frame. As you have seen in the above example, two or more frames can be changed simply by targeting the _parent of a nested frameset document. This will not always suffice however, and you may find it easier to use the JavaScript method illustrated below:

<BODY onLoad="parent.frameName.location='http://domain.com/page.html'">

Including this simple command in any document of your frameset will cause the specified frame NAME to be updated with the specified URL. Simply put, you will change the first frame in your sequence with the normal href="" target="frameName" method, and that new document will cause the next frame in your sequence to load the appropriate page.