Online Book Reader

Home Category

HTML, XHTML and CSS All-In-One for Dummies - Andy Harris [43]

By Root 1320 0
one kind of address. So far, you’ve seen only absolute references, used for links to outside pages. Another kind of reference — a relative reference — links multiple pages inside your own Web site.


Understanding absolute references

The type of link used in basicLinks.html is an absolute reference. Absolute references always begin with the protocol name (usually http://). An absolute reference is the complete address to a Web page, just as you’d use in the browser’s address bar. Absolute references are used to refer to a site somewhere else on the Internet. Even if your Web site moves (say, from your desktop machine to a Web server somewhere on the Internet), all the absolute references will work fine because they don’t rely on the current page’s position for any information.


Introducing relative references

Relative references are used when your Web site includes more than one page. You might choose to have several pages and a link mechanism for moving among them. Figure 5-3 shows a page with several links on it.

Figure 5-3: These little piggies sure get around.

The page isn’t so interesting on its own, but it isn’t meant to stand alone. When you click one of the links, you go to a brand-new page. Figure 5-4 shows what happens when you click the market link.

Figure 5-4: The market page lets you move back.

The market page is pretty simple, but it also contains a link back to the initial page. Most Web sites aren’t single pages at all, but an interconnected web of pages. The relative reference is very useful when you have a set of pages with interlacing links.

The code for pigs.html shows how relative references work:

“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>

pigs.html

Destinations of Porcine Mammals

Most of the code is completely familiar. The only thing surprising is what’s not there. Take a closer look at one of the links:

home.

There’s no protocol (the http:// part) and no address at all, just a filename. This is a relative reference. Relative references work by assuming the address of the current page. When the user clicks market.html, the browser sees no protocol, so it assumes that market.html is in the same directory on the same server as pigs.html.

Relative references work like directions. For example, if you’re in my lab and ask where the water fountain is, I’d say, “Go out into the hallway, turn left, and turn left again at the end of the next hallway.” Those directions get you to the water fountain if you start in the right place. If you’re somewhere else and you follow the same directions, you don’t really know where you’ll end up.

Relative references work well when you have a bunch of interconnected Web pages. If you create a lot of pages about the same topic and put them in the same directory, you can use relative references between the pages. If you decide to move your pages to another server, all the links still work correctly.

In Book VIII, you discover how to set up a permanent Web server. It’s often most convenient to create and modify your pages on the local machine and then ship them to the Web server for the world to see. If you use relative references, it’s easy to move a group of pages together and know the links will still work.

If you’re referring to a page on somebody else’s site, you have to use an absolute reference. If you’re linking to another page

Return Main Page Previous Page Next Page

®Online Book Reader