Frames - Part 3 from Chapter 11 of HTML & XHTML: The Definitive Guide (4/4)
[previous] |
HTML & XHTML: The Definitive Guide, Chapter 11: Frames
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, you can add a target
attribute to the <base>
tag.
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, almost every link causes the document to be displayed in another window named "view_frame." Rather than including that target in each hypertext link, you should place the common target in the table of contents's <base>
tag within its <head>
:
<head>
<title>Table of Contents</title>
<base target="view_frame">
</head>
<body>
<h3>Table of Contents</h3>
<ul>
<li><a href="pref.html">Preface</a></li>
<li><a href="chap1.html">Chapter 1</a></li>
<li><a href="chap2.html" >Chapter 2</a></li>
<li><a href="chap3.html">Chapter 3</a></li>
</ul>
</body>
Notice that we don't include any other target references in the list of hyperlinks, because the browser loads and displays all the respective documents in the base target "view_frame."
Traditional Link Behavior
Before the onset of frames, each time you selected 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 it 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 are 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 him to a different site? The referenced document is still 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![1] Very impolite.
The solution is to make sure that every hypertext link that references a remote document has a target of _top
. This way, when the user selects a link that takes him away from your site, the remote document replaces the contents of the entire browser window, including your navigation and feedback frames. If the majority of the links in your documents are to other sites, you might consider adding target="_top"
to a <base>
tag in your document and using explicit target
attributes in the links to your local documents.
1. Check out Chapter 17 for how to step out into the forefront when your pages happen to be on the other end of a targetless hyperlink. [Back]
[previous] |
Created: November 25, 2002
Revised: November 25, 2002
URL: https://webreference.com/authoring/languages/html/definitive/3/4.html