Thursday, April 1, 2010
Setting the Default Path
When defining links and references in your HTML document, be as exact as possible
with your references. For example, when referencing a graphic with an <IMG> tag,
you should make a habit of including the protocol and the full path to the graphic, as
shown in the following line of code:
<img src-"http://www.example.com/images/sailboat.gif">
However, it isn’t very practical to type the full path to every local element that is
referenced in your document. As such, a document residing on the example.com
server could reference the same graphic with the following code:
<img src-"images/sailboat.gif">
But, what happens if the document is relocated? The images directory might no
longer be a subdirectory of the directory where the document resides. The image
might be on a separate server altogether.
To solve these problems, you could use the <base> tag. The <base> tag sets the
default document base-that is, the default location for the document. Using the
preceding example, a document in the root directory of the example.com server
would have a <base> tag similar to the following:
Any absolute references in the document (those with full protocol and path) will
continue to point to their absolute targets. However, any relative reference (those
without full protocol and path) will be referenced against the path in the <base> tag.


Currently have 0 comments: