HTML: The Definitive Guide

Previous Chapter 10 Next
 

10.6 Named Frame or Window Targets

As we discuss above in the <frame> tag description section, you can label a frame by adding the name attribute to its <frame> tag. Once named, the frame may become the destination display window for a hypertext-linked document selected within a document displayed in some other frame. You accomplish this redirection by adding a special, Netscape-only (version 2.0 or later) target attribute to the anchor that references the document.

The target Attribute for the <a> Tag

If you include a target attribute within an <a> tag, Netscape will load and display the document named in the tag's href attribute in a frame or window whose name matches the target. If the named frame or window doesn't exist, Netscape will open a new window, give it the target's name, and load the new document into that window. Thereafter, hypertext-linked documents that target that name will load into the new window.

Targeted hypertext links makes it easy to create effective navigational tools. A simple table of contents document, for example, might redirect documents into a separate window:

<h3>Table of Contents</h3>
<ul>
  <li><a href="pref.html" target="view_window">Preface</a>
  <li><a href="chap1.html" target="view_window">Chapter 1</a>
  <li><a href="chap2.html" target="view_window">Chapter 2</a>
  <li><a href="chap3.html" target="view_window">Chapter 3</a>
</ul>

The first time the user clicks one of the table of contents hypertext links, Netscape will open a new window, name it ``view_window,'' and display the desired document's contents inside it. If the user selects another link from the example table of contents and the ``view_window'' is still open, Netscape will again load the selected document into that window, replacing the previous document.

Throughout the whole process, the window containing the table of contents is accessible to the user. By clicking on a link in one window, the user causes the contents of the other window to change.

Similarly, you can place the table of contents into one frame of a two-frame document and use the adjacent frame for display of the selected documents:

<frameset cols="150,*">
  <frame src="toc.html">
  <frame src="pref.html" name="view_window">
</frameset>

When Netscape initially displays the two frames, the left frame contains the table of contents, and the right frame contains the preface (Figure 10-4).

When a user selects a link from the table of contents in the left frame, Chapter 1 for example, Netscape loads and displays the associated document into the ``view_window'' frame on the right side (Figure 10-5). As other links are selected, the lower frame's contents change, while the upper frame continuously makes the table of contents available to the user.

Special Targets

Netscape has reserved four target names for special document redirection actions. They are:

_blank

Netscape always loads a target="_blank" linked document into a newly opened, unnamed window.

_self

This target value is the default for all <a> tags that do not specify a target, causing the target document to be loaded and displayed in the same frame or window as source document. This target is redundant and unnecessary unless used in combination with the target attribute in Netscape's special <base> tag in a document's head (see below).

_parent

The _parent target causes the document to be loaded into the parent window or frameset containing the frame containing the hypertext reference. If the reference is in a window or top-level frame, it is equivalent to the target _self.

A brief example may help clarify how this link works. Consider a link in a frame that is part of a three-column frameset. This frameset, in turn, is a row in the top-level frameset being displayed in the browser window. This arrangement is shown in Figure 10-6.

If no target were specified for the hypertext link, it would be loaded into the containing frame. If a target of _parent were specified, the document is loaded into the area occupied by the three-column frameset containing the frame containing the link.

_top

This target causes the document to be loaded into the window containing the hypertext link, replacing any frames currently displayed in the window.

Continuing with the frame hierarchy shown in Figure 10-6, using a target of _top would remove all the contained frames and load the document into the entire browser window.

All four of these names begin with the underscore (_) character. Any other window or target name beginning with an underscore is ignored by the browser. Don't use the underscore as the first character of the name of any frame you define in your documents.

The <base> Default Target

It can be tedious to specify a target for every hypertext link in your documents, especially when most are targeted at the same window or frame. To alleviate this problem, Netscape lets you add a target attribute to its <base> tag. [<base>, 6.7.1]

The target attribute in the <base> tag sets the default target for every hypertext link in the current document that does not contain an explicit target attribute. For example, in our example table of contents document, most every link causes the document to be displayed in another window named ``view_window.'' Rather than include that target in each hypertext link, you should place the common target in the table of contents' <base> tag within its <head>:

<html>
<head>
<title>Table of Contents</title>
<base target="view_window">
</head>
<body>
<h3>Table of Contents</h3>
<ul>
  <li><a href="pref.html">Preface</a>
  <li><a href="chap1.html">Chapter 1</a>
  <li><a href="chap2.html" >Chapter 2</a>
  <li><a href="chap3.html">Chapter 3</a>
</ul>
</body>
</html>

Notice we don't include any other target references in the list of hyperlinks because Netscape will load and display all the respective documents in the base target ``view_window.''

Traditional link behavior

Before the onset of frames, each time you clicked on a hyperlink, the corresponding document replaced the contents of the browser window. With frames, this behavior is modified so that the corresponding document replaces the content of the referencing frame. This is often not the desired behavior and can be disconcerting to people browsing your documents.

For example, suppose you have arranged all of the documents on your site to present themselves in three frames: a navigational frame at the top of the browser window, a scrolling content frame in the middle, and a feedback form at the bottom. You named the content frame with the name attribute of the <frame> tag in the top-level document for your collection and used the target attribute of the <base> tag in every document on your site to ensure that all links will be loaded into the center content frame.

This arrangement works perfectly for all the documents on your site, but what happens when a user selects a link that takes them to a different site? The referenced document will still be loaded into the center content frame. Now the user is confronted by a document from some other site, surrounded by your navigation and feedback frames!

The solution is to make sure that every hypertext link that references a remote document has a target of _top. This way, when someone selects a link that takes them away from your site, the remote document will replace the contents of the entire browser window, including your navigation and feedback frames.


Previous Home Next
The <noframes> Tag Book Index Netscape Dynamic Documents