ptg16476052
110 LESSON 6: Working with Links
Linking to Elements in the Same Document
What if you have only one large page, and you want to link to sections within that page?
You can link to them as well. For longer pages, using IDs can be an easy way to jump
around within sections. To link to sections, you just need to add IDs to each section the
way you usually do. Then, when you link to those IDs, leave off the name of the page
itself, but include the hash sign and the ID. So, if you’re linking to an element with the
ID section5 in the same page as the link, the link looks like the following:
Go to <a href="#section5">The Fifth Section</a>
When you leave off the page name, the browser assumes that you’re linking to the cur-
rent page and scrolls to the appropriate section. You’ll get a chance to see this feature in
action in Lesson 7. There, you’ll create a complete web page that includes a table of con-
tents at the beginning. From this table of contents, the reader can jump to different sec-
tions in the same web page. The table of contents includes links to each section heading.
In turn, other links at the end of each section enable the user to jump back to the table of
contents or to the top of the page.
Anatomy of a URL
So far in this book, you’ve encountered URLs twice: in Lesson 1, “What Is Web
Publishing?,” as part of the introduction to the Web; and in this lesson, when you created
links to remote pages. If you’ve ever done much exploring on the Web, you’ve encoun-
tered URLs as a matter of course. You couldn’t start exploring without a URL.
As I mentioned in Lesson 1, URLs are uniform resource locators. In effect, URLs are
street addresses for bits of information on the Internet. Most of the time, you can just
navigate to the page to which you want to link in your browser and copy the URL from
the address bar into your link. But understanding what a URL is all about and why it can
sometimes be so long and complex is useful. Also, when you put your own information
up on the Web, knowing something about URLs will be useful so that you can tell people
where your web page is.
In this section, you learn what the parts of a URL are, how you can use them to get to
information on the Web, and the kinds of URLs you can use (HTTP, FTP, mailto, and so
on).
Parts of URLs...........................................................................................
Most URLs contain (roughly) three parts: the protocol, the hostname, and the directory or
filename (see Figure 6.14).