ptg16476052
112 LESSON 6: Working with Links
an identifier. For the files you’ll be working with while learning HTML, the directory
information will point to files that exist on your computer. The path of the root URL on a
server is just /, as in http://www.example.com/.
After the path, some URLs include a query. The query is separated from the rest of the
URL by a question mark. The query is made up of name and value pairs, separated by
ampersands (&). An equals sign (=) separates the names and values. Here’s an example:
http://www.example.com/search?q=urls
The query portion of a URL isn’t typically used with regular HTML files, but it can be
accessed by web applications and can be used with JavaScript. These query parameters
will not be discussed much in this book, but you’ll see an awful lot of them when you’re
visiting websites.
The final part of a URL is the anchor, which was described in the previous section.
Special Characters in URLs
A special character in a URL is anything that is not an upper- or lowercase letter, a num-
ber (0–9), or one of the following symbols: dollar sign ($), dash (-), underscore (_), or
period (.). You might need to specify any other characters by using special URL escape
codes to keep them from being interpreted as parts of the URL itself.
These special characters are replaced by codes that consist of a percent sign followed
by two hexadecimal digits, which consist of digits (0–9) and letters (A–F). For example,
once a URL has been encoded, %20 replaces a space, %3f replaces a question mark, and
%2f replaces a slash. (Spaces are also sometimes encoded as + signs, and + signs are
encoded as %2b.) The need for encoding these characters makes sense because such char-
acters can have a specific meaning when seen within a URL. The slash is the path separa-
tor in a URL, and a question mark separates the path in a URL from the query. Spaces
that aren’t encoded are hard to interpret in many contexts.
Suppose that you have a directory named All My Files. Your first pass at a URL with
this name in it might look like the following:
http://myhost.com/harddrive/All My Files/www/file.html
If you put this URL in quotation marks in a link tag, it might work (but only if you put
it in quotation marks). Because the spaces are considered special characters to the URL,
however, some browsers might have problems with them and not recognize the pathname
correctly. For full compatibility with all browsers, use %20, as follows :
http://myhost.com/harddrive/All%20My%20Files/www/file.html