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.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.

Watch Out!

The <base /> tag has no effect on the URL of pages specified in the <meta /> tag that are automatically loaded after a certain delay. This explains why the full URL for the news.html page is provided in the <meta /> tag in Listing 23.3.


By the Way

Few web page authors use (or even know about) the <base /> tag. Many who do know about it don't like the hassle of changing it when they want to test a page (including images and links) on their hard drive. I've tried to give you enough information in this hour to choose for yourself whether the <base /> tag is worthwhile for youyou may very well decide that it's not.

If you do choose to use the <base /> tag, don't put it in your pages until you're ready to upload them to the web server. That way you can test them with all the images and link pages on your hard drive and then add the <base /> tag at the last minute, to enjoy the benefits it offers after your pages are online.





SAMS Teach Yourself HTML and CSS in 24 Hours
Sams Teach Yourself HTML and CSS in 24 Hours (7th Edition)
ISBN: 0672328410
EAN: 2147483647
Year: 2005
Pages: 345

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net