Sams Teach Yourself HTML, CSS & JavaScript Web Publishing in One Hour a Day

(singke) #1
ptg16476052

116 LESSON 6: Working with Links


Unlike the other URLs described here, the mailto URL works strictly on the client side.
The mailto link just tells the browser to compose an email message to the specified
address. It’s up to the browser to figure out how that should happen. Most browsers will
also let you add a default subject to the email by including it in the URL like this:
mailto:[email protected]?subject=Hi there!
When the user clicks the link, most browsers will automatically stick Hi there! in the
subject of the message. You can also define Cc and Bcc addresses like this:
mailto:[email protected][email protected]
Some even support putting body text for the email message in the link with the body=
query. Then you can combine them all together, like this :
mailto:[email protected]?subject=Hi [email protected]&body=Body text.

File


File URLs are intended to reference files contained on the local disk. In other words, they
refer to files located on the same system as the browser. For local files, URLs have an
empty hostname (three slashes rather than two):
file:///dir1/dir2/file
You’ll use file URLs a lot when you’re testing pages you’ve created locally, although it’s
easier to use the browser’s “Open File” functionality or drag and drop to open local files
in your browser than it is to type in a file URL. Another use of file URLs is to create a
local startup page for your browser with links to sites you use frequently. In this instance,
because you’ll be referring to a local file, using a file URL makes sense.
The problem with file URLs is that they reference local files, where local means on the
same system as the browser pointing to the file—not the same system from which the
page was retrieved! If you use file URLs as links in your page, and someone from else-
where on the Internet encounters your page and tries to follow those links, that person’s
browser will attempt to find the file on her local disk (and generally will fail). Also,
because file URLs use the absolute pathname to the file, if you use file URLs in your
page, you can’t move that page elsewhere on the system or to any other system.

If your email address includes a percent sign (%), you have to use
the escape character %25 instead. Percent signs are special char-
acters to URLs and thus to mailto URLs.

NOTE
Free download pdf