Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Documenting the Full Address of a Page

Suppose you create a Web page advertising your business, and a customer likes your page so much that she saves it on her hard drive. A couple of days later, she wants to show a friend your cool site, but guess what? She forgot to bookmark it, and of course the page doesn't contain a link to itself. She clicks the links to your order form, but they are only filename links (such as <a href="orderform.htm">); they don't work from her hard drive unless the order form is on her hard drive, too. You have lost two eager customers.

One way to avoid this heartbreaking scenario is to always use complete addresses starting with http:// in all links. However, this makes your pages difficult to test and maintain.

You could also include a link to your home page's full address on every page, including the home page itself. Yet there's a more elegant way to make a page remember where it came from.

The <base /> tag lets you include the address of a page within the <head> section of that page, like this:

<html><head>
 <title>My Page</title>
 <base href="http://www.myplace.com/mypage.htm" />
</head>
<body> …The actual page goes here… </body>
</html>

For the HTML authors whose job is to maintain this page, the <base /> tag provides convenient documentation of where this page should be put.

Even more importantly, all links within the page behave as if the page was at the <base /> address—even if it isn't. For example, if you had the page in Figure 23.7 on your hard drive and you opened it with a Web browser, all images on the page would be loaded from the online site at http://netletter.com/nicholas/ rather than from the hard drive. The links would also lead to pages in the nicholas directory at http://netletter.com, instead of pages on the hard drive.

Share ThisShare This

Informit Network