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.html">); 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 scenario is to always use complete addresses starting with http:// in all links. However, this makes your pages difficult to test and maintain. If you ever move your site or change the domain name, all of your links are suddenly broken. 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/" /> </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 important, all links within the page behave as if the page were at the <base /> addresseven if it isn't. For example, if you had the page in Listing 23.3 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://www.stalefishlabs.com/ rather than from the hard drive. In fact, the images are actually stored in a folder called images beneath the root web folder, which explains why the links in the listing begin with images/ before the image filename. The link to the news.html page also leads to a page in the root folder at http://www.stalefishlabs.com/, instead of a local page on the hard drive.
|