Links

Introduction

A link instructs the web browser to get a service, from a named computer, within a named location on that computer and at a named point within the file thus located. A link is usually executed by clicking on the link with the mouse with the current webpage being replaced with the contents of the linked Web service. A link may consist of four distinct parts.

Example

"http:// www.treeleaves.org.uk /html/links.html #section1"
  • "#section1" specifies the named point, or fragment name, within the above file.
  • "/html/links.html" specifies the file location, or directory path, on the above computer.
  • "www.treeleaves.org.uk" specifies the computer.
  • "http://" specifies the type of web service.

Fragment Name

Links are incorporated within or between webpages, by specifying anchor points. Such an anchor point can be a destination or source anchor. The <a> and </a> tags define an anchor. A local fragment is a place marker or bookmark within a webpage. The fragment identifier is specified by using the name attribute within an anchor tag. The name of the tag is prefixed with a #, when it is included within a URI.

<a href="#name1">Name1</a>

The top of the webpage is displayed if no fragment identifier is included.

Example

The following code shows the HTML for a link, which is within this document.

This is Tag 1

<a name="Tag1">This is Tag 1</a> <p>.</p> <p>.</p> <a href="#Tag1">Go to Tag 1</a>
This is Tag 1

.

.

Go to Tag 1

Files

Links can be made to text files, which can then be opened.

Example

The following is the code for linking to a text file.

<a href="src/txt/trees.txt">../src/txt/trees.txt</a>
../src/txt/trees.txt

Directories

Links can be made to directories, the contents of which can then be displayed.

Example

The following is the code for linking to a directory.

<a href="images">images</a>
images

Images

Links can be made to image files, which can then be opened.

Example

The following is the code for linking to an image.

<a href="src/uk/co/treeleaves/html/elements/yellowcar.gif">src/uk/co/treeleaves/html/elements/yellowcar.gif</a>
src/uk/co/treeleaves/html/elements/yellowcar.gif