HTML and CSS Reference
In-Depth Information
to use symbolic links on the Web server to reference one copy of the file from multiple
locations. However, because HTML is the subject here, we focus on the former solution
using the base element.
The base element defines the base for all relative URLs within a document. Setting the
href attribute of this element to a fully qualified URL enables all other relative references to
use the defined base. For example, if <base> is set as <base href="http://www.htmlref
.com/"> , then all the anchors in the document that aren't fully qualified will prefix http://
www.htmlref.com/ to the destination URL. Because base is an empty element, it would have
to be written as <base href="http://www.htmlref.com/" /> to be XHTML-compliant.
A simple example is presented here:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> Base URL Example </title>
<base href="http://htmlref.com/">
</head>
<body>
<ul>
<li><a href="AppD/basiclink.html"> Basic linking example </a></li>
<li><a href="AppD/base.html"> Base example </a></li>
<li><a href="."> Book Site Home Page </a></li>
<li><a href="http://htmlref.com"> Book Site Home Page Alternate </a></li>
<li><a href="http://www.google.com"> Google </a></li>
</ul>
</body>
</html>
O NLINE http://htmlref.com/AppD/base.html
It is most interesting to run this example from another server or locally off your disk, as you
will note that the relative URLs will resolve to the topic support site per the address in the
<base> tag.
Since a <base> tag can occur only once in an HTML document—within the head
element—creating sections of a document with different base URL values is impossible.
Such a feature might someday be added to a sectioning element, but until then, HTML
authors have to deal with the fact that shorthand notation is useful only in some places. See
the entry in Chapter 3 for more information on the <base> tag.
URL Challenges
While we all know and use URLs, we don't necessarily understand all their little quirks. We
enumerate a few of the more common challenges faced when working with URLs here.
Search WWH ::




Custom Search