home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

HTML 4.0 Sourcebook
(Publisher: John Wiley & Sons, Inc.)
Author(s): Ian S. Graham
ISBN: 0471257249
Publication Date: 04/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Uniform Resource Locators

The target of the hypertext link is indicated by the anchor attribute HREF, which takes as its value the Uniform Resource Locator (URL) of the target document or resource. As mentioned in the Preface, a URL is a text string that indicates the server protocol (HTTP, FTP, WAIS, etc.) to use in accessing the resource, the Internet domain name of the server, and the name and location of the resource on that particular server. Obviously, the HREF attributes in Figure 1.4 do not contain all this information! These URLs are examples of partial URLs, which are a shorthand way of referring to files or other resources relative to the URL of the document currently being viewed. For Figure 1.4, this means: Use the same mechanism used to retrieve the present document (ex2a.html) and retrieve the indicated file ex2b.html (see Figures 1.9 and 1.10) from the same directory. This works whether the files are on a local computer or on a Web server half-way around the world.


Figure 1.9 Contents of the example HTML document ex2b.html. This document is the target of a hypertext link from the file ex2a.html shown in Figure 1.4.

<HTML>

<HEAD>
<TITLE> Example 2B: Target of example Hypertext Link</TITLE>
</HEAD>
<BODY>

<h2> Target of Hypertext Link </h2>

<P> OK, so now that you are here, how do you get back?  This document
    doesn't have any hypertext links, so you have to use a “back” button (or the
    ‘u’ key if using lynx) to move back to the previously viewed document.


</BODY></HTML>


Figure 1.10  Internet Explorer 4 rendering of the HTML document ex2b.html (the HTML document source is listed in Figure 1.9).


Figure 1.11  Netscape Navigator 4 rendering of the HTML document ex2a.html after returning from a hypertext jump to the document ex2b.html.

If you click the mouse button over the hypertext anchor, the browser downloads and displays the linked document, as shown in Figure 1.10. To return to the previously viewed document, press the Back button on the browser control panel (with lynx, press the letter “u”, for up), which takes you back to the previously displayed document, namely ex2a.html. Figure 1.11 shows, for Navigator 4, what this document looks like the second time around. The document is now subtly different: The portion of text that served as the launching point for the hypertext link, previously underlined in blue, is now underlined by a faded, purple line (this does not show up well in this black-and-white figure). Graphical browsers use such highlighting changes to keep users oriented by letting them know where they have already been. Unfortunately, this is not possible with lynx, as there are too few text highlighting modes to allow this level of subtlety. With lynx, users must pay a bit more attention to what they have been doing and where they have been.

Relative Uniform Resource Locators: Linking Documents Together

As mentioned, the anchor

<A HREF=“ex2b.html”>hypertext links</A>

uses a partial URL, which references a location relative to the URL of the displayed document. This partial URL idea is great news, because it means that you need not specify entire URLs for simple links between files on the same computer.


Figure 1.12  Accessing neighboring files using partial URLs. The dotted lines and the associated text strings illustrate partial URLs relating the file ex2a.html to the files ex2b.html, ex2c.html, and ex2d.html. The grayed directory, cgi-bin, indicates a gateway program directory—this directory contains programs to be executed by the HTTP server. The figure shows these folders and files as lying in the Document Directory—the directory, on a Web server, that contains the resources available via the Web. Material not under the document directory, such as the file file.html, are inaccessible to the outside world.

Instead, you need only specify their position on the file system relative to each other, as done in Figure 1.4.

Partial URLs can point to directories other than the one containing the current document. Specification of these relative directories is done using a UNIX-like path structure, as illustrated in Figure 1.12. Suppose that the example documents ex2a.html and ex2b.html lie in the indicated directory structure. That is, the files ex2a.html and ex2b.html are in the directory Examples/, while the file ex2c.html is in Examples/SubDir/, and ex2d.html is in /Other/.

How do you reference the files ex2c.html and ex2d.html from the file ex2a.html? To reference ex2c.html, simply create a hypertext link that accesses the partial URL SubDir/ex2c.html:

<A HREF=“SubDir/ex2c.html”>hypertext links</A>

Notice that the pathnames use the forward slash characters to indicate a new directory. The URL specification states that the forward slash—and no other character—delimits directories or other hierarchical relationships (formally, URLs can reference not just files, but also programs or other resources). You cannot use backslashes (\) as you do with DOS and Windows or colons (:) as you do on Macintoshes.

If you want to create a link from ex2a.html to ex2d.html in the directory Other/, you write the URL as

<A HREF=“../Other/ex2d.html”>hypertext links</A>

since the file is one directory level up—in partial URLs, the symbol “..” indicates a resource one directory up from the current directory—and one level down into the directory Other. A single dot (.) in a URL indicates the current directory, so HREF=“./Subdir/ex2c.html” and HREF=“Subdir/ex2c.html” are equivalent.

Special Characters in a URL

Of course, this scheme will cause problems if you actually use a slash character as part of a filename, since the URL convention will try to interpret it as a directory change. It is therefore best to avoid directory or file names containing this character. The URL syntax does have a way of allowing this and other special characters within a URL. The required encoding mechanism is discussed in Chapter 8.

There are a lot of other partial URL forms and, of course, we have yet to properly discuss full URLs. More URL examples appear later in this chapter as well as in Chapter 2, while the details of the URL syntax is given Chapter 8.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.