The Web Design Group

Web Authoring FAQ: HTML Frames


This list of Frequently Asked Questions is maintained by the WDG and was last updated on November 29, 1999. It may be found at the following URLs:

If you would like to contribute to this FAQ, please send mail to <darin@htmlhelp.com>. All contributors will be listed at the bottom of the FAQ.

8. HTML Frames

  1. How do I make a link or form in one frame update another frame?
  2. Why do my links open new windows rather than update an existing frame?
  3. How do I update two frames at once?
  4. How do I get out of a frameset?
  5. How do I make sure my framed documents are displayed inside their frameset?
  6. Is there a way to prevent getting framed?
  7. How do I specify a specific combination of frames instead of the default document?
  8. How do I remove the border around frames?
  9. How do I change the title of a framed document?
  10. Why aren't my frames the exact size I specified?
  11. Are there any problems with using frames?

8.1. How do I make a link or form in one frame update another frame?

In the frameset document (the HTML document containing the <FRAMESET> and <FRAME> elements), make sure to name the individual frames using the NAME attribute. The following example creates a top frame named "navigation" and a bottom frame named "content":

<FRAMESET ROWS="*,3*">
    <FRAME NAME="navigation" SRC="navigation.html">
    <FRAME NAME="content" SRC="content.html">
    <NOFRAMES><BODY>
        <!-- Alternative non-framed version -->
    </BODY></NOFRAMES>
</FRAMESET>

Then, in the document with the link, use the TARGET attribute to specify which frame should be used to display the link. (The value of the TARGET attribute should match the value of the target frame's NAME attribute.) You can specify the target frame for a link (e.g., <A TARGET="content" HREF=...>) or for a form (e.g., <FORM TARGET="content" ACTION=...>). Also, you can use <BASE TARGET=...> to change the default target frame for the entire document (normally, the default target frame is "_self", the current frame).

[Table of Contents]

8.2. Why do my links open new windows rather than update an existing frame?

If there is no existing frame with the name you used for the TARGET attribute, then a new browser window will be opened, and this window will be assigned the name you used. Furthermore, TARGET="_blank" will open a new, unnamed browser window.

In HTML 4.0, the TARGET attribute value is case-insensitive, so that abc and ABC both refer to the same frame/window, and _top and _TOP both have the same meaning. However, most browsers treat the TARGET attribute value as case-sensitive and do not recognize ABC as being the same as abc, or _TOP as having the special meaning of _top.

[Table of Contents]

8.3. How do I update two frames at once?

There are two basic techniques for updating multiple frames with a single link: The HTML-based technique links to a new frameset document that specifies the new combination of frames. The JavaScript-based solution uses the onClick attribute of the link to update the additional frame (or frames).

The HTML-based technique can link to a new frameset document with TARGET="_top" (replacing the entire frameset), but there is an alternative if the frames to be updated are part of a nested frameset. In the initial frameset document, use a secondary frameset document to define the nested frameset. For example:

<FRAMESET COLS="*,3*">
    <FRAME SRC="contents.html" NAME="Contents">
    <FRAME SRC="frameset2.html" NAME="Display">
</FRAMESET>

A link can now use TARGET="Display" to replace simultaneously all the frames defined by frameset2.html.

The JavaScript-based solution uses the onClick attribute of the link to perform the secondary update. For example:

<A HREF="URL1" TARGET=Frame1
   onClick="top.Frame2.location='URL2';">Update frames</A>

The link will update Frame1 with URL1 normally. If the reader's browser supports JavaScript (and has it enabled), then Frame2 will also be updated (with URL2).

[Table of Contents]

8.4. How do I get out of a frameset?

If you are the author, this is easy. You only have to add the TARGET attribute to the link that takes readers to the intended 'outside' document. Give it the value of _top.

In many current browsers, it is not possible to display a frame in the full browser window, at least not very easily. The reader would need to copy the URL of the desired frame and then request that URL manually.

I would recommend that authors who want to offer readers this option add a link to the document itself in the document, with the TARGET attribute set to _top so the document displays in the full window if the link is followed.

[Table of Contents]

8.5. How do I make sure my framed documents are displayed inside their frameset?

When the sub-documents of a frameset state are accessed directly, they appear without the context of the surrounding frameset.

If the reader's browser has JavaScript support enabled, the following script will restore the frameset:

<SCRIPT TYPE="text/javascript">
<!--
if (parent.location.href == self.location.href) {
    if (window.location.replace)
        window.location.replace('frameset.html');
    else
        // causes problems with back button, but works
        window.location.href = 'frameset.html';
}
//  -->
</SCRIPT>

A more universal approach is a "restore frames" link:

<A HREF="frameset.html" TARGET="_top">Restore Frames</A>

Note that in either case, you must have a separate frameset document for every content document. If you link to the default frameset document, then your reader will get the default content document, rather than the content document he/she was trying to access. These frameset documents should be generated automatically, to avoid the tedium and inaccuracy of creating them by hand.

Note that you can work around the problem with bookmarking frameset states by linking to these separate frameset documents using TARGET="_top", rather than linking to the individual content documents.

[Table of Contents]

8.6. Is there a way to prevent getting framed?

"Getting framed" refers to having your documents displayed within someone else's frameset without your permission. This can happen accidentally (the frameset author forgot to use TARGET="_top" when linking to your document) or intentionally (the frameset author wanted to display your content with his/her own navigation or banner frames).

To avoid "framing" other people's documents, you must add TARGET="_top" to all links that lead to documents outside your intended scope.

Unfortunately, there is no reliable way to specify that a particular document should be displayed in the full browser window, rather than in the current frame. If you can configure your server to send the proprietary header Window-Target: _top in the HTTP response, then Netscape browsers will display your document in the full browser window. However, other browsers ignore this header, and it doesn't work to use <META HTTP-EQUIV="Window-target" CONTENT="_top"> in the document itself to mimic the HTTP response.

Another workaround is to use <BASE TARGET="_top"> in the document, but this only specifies the default target frame for links in the current document, not for the document itself.

If the reader's browser has JavaScript enabled, the following script will automatically remove any existing framesets:

<SCRIPT TYPE="text/javascript">
<!--
if (top.frames.length!=0)
    top.location=self.document.location;
// -->
</SCRIPT>

An alternative script is

<SCRIPT TYPE="text/javascript">
<!--
function breakOut() {
    if (self != top) 
        window.open("my URL","_top","");
}
// -->
</SCRIPT>
</HEAD>
<BODY onLoad="breakOut()">

[Table of Contents]

8.7. How do I specify a specific combination of frames instead of the default document?

This is unfortunately not possible. When you navigate through a site using frames, the URL will not change as the documents in the individual frames change. This means that there is no way to indicate the combination of documents that make up the current state of the frameset.

The author can provide and link to multiple frameset documents, one for each combination of frame content. These frameset documents can be generated automatically, possibly even being created on the fly by a CGI program.

[Table of Contents]

8.8. How do I remove the border around frames?

Removing the border around frames involves both not drawing the frame borders and eliminating the space between the frames. The two major frames-capable browsers use different proprietary attributes to achieve this.

Netscape recognizes the BORDER attribute on FRAMESET. It can be set to 0, in which case the border will not be shown, and the spacing will be set to zero.

Microsoft Internet Explorer recognizes the FRAMEBORDER and FRAMESPACING attributes on FRAMESET, but in some versions also on FRAME for individual frames. Both attributes must be set to 0.

So, the most widely supported way to display borderless frames is <FRAMESET ... BORDER=0 FRAMEBORDER=0 FRAMESPACING=0>.

Note that these attributes are proprietary and not part of the HTML 4.0 specification. Also, removing the border around a frame makes it impossible to resize it, as this border is also used in most GUIs to change the size of the window.

[Table of Contents]

8.9. How do I change the title of a framed document?

The title displayed is the title of the frameset document rather than the titles of any of the pages within frames. To change the title displayed, link to a new frameset document using TARGET="_top" (replacing the entire frameset).

[Table of Contents]

8.10. Why aren't my frames the exact size I specified?

Netscape Navigator seems to round pixel-based frame dimensions to the nearest whole percentage, and to use those percentage-based dimensions when laying out the frames. Thus, frames with pixel-based dimensions will be rendered with a slightly different size than that specified in the frameset document. There is no way to prevent this behavior, and the rounding error will vary depending on the exact size of the browser window.

To accomodate this, you should design your site to adapt to variations in the browser's presentation. This is a good idea in general, but especially so in this situation.

[Table of Contents]

8.11. Are there any problems with using frames?

The fundamental problem with the design of frames is that framesets create states in the browser that are not addressable. Once any of the frames within a frameset changes from its default content, there is no longer a way to address the current state of the frameset. It is difficult to bookmark - and impossible to link or index - such a frameset state. It is impossible to reference such a frameset state in other media. When the sub-documents of such a frameset state are accessed directly, they appear without the context of the surrounding frameset. Basic browser functions (e.g., printing, moving forwards/backwards in the browser's history) behave differently with framesets.

Furthermore, frames focus on layout rather than on information structure, and many authors of framed sites neglect to provide useful alternative content in the <NOFRAMES> element. Both of these factors cause accessibility problems for browsers that differ significantly from the author's expectations and for search engines.

For further discussion, see <URL:http://www.htmlhelp.com/design/frames/whatswrong.html>

[Table of Contents]


For additions or omissions to this FAQ, please contact <darin@htmlhelp.com>.

All information contained herein was originally compiled by members of the Web Design Group, principally Arnoud "Galactus" Engelfriet, John Pozadzides, and Darin McGrew.

Additional input has been provided by Boris Ammerlaan, Lori Atwater, Alex Bell, Stan Brown, Roger Carbol, Alex Chapman, Jan Roland Eriksson, Jon Erlandson, Mark Evans, Alan Flavell, Lucie Gelinas, Bjoern Hoehrmann, Tina Marie Holmboe, Peter Jones, Nick Kew, Jukka Korpela, Simon Lee, Nick Lilavois, Neal McBurnett, Glen McDonald, Dan McGarry, Ken O'Brien, Timothy Prodin, Steve Pugh, Liam Quinn, Colin Reynolds, Kai Schätzl, Doug Sheppard, Sue Sims, Toby Speight, Warren Steel, Ian Storms, Peter Thomson, Daniel Tobias, and Diane Wilson.

Thanks everyone!


Home, Reference, FAQs, Tools, Design, Feature Article, BBS, Links

Copyright © 1996-1999. Web Design Group All rights reserved.