[Contents] [Previous] [Next] [Alphabetical Tag List] [Index]

HTML Tag Reference

Anchors and Links

This section discusses the A tag which is used to define anchors (places in a document that can be linked to) and also to create links.


A

(anchor or link)

The A tag lets you define anchors and links. An anchor defines a place in a document. A link displays a hypertext link that the user can click to display an anchor or a document.

A as anchor

An anchor identifies a place in an HTML document. To indicate that an <A> tag is being used as an anchor, specify the NAME attribute.

Note that you can also use the ID attribute of any tag to identify that tag as an anchor, as discussed in Universal Attributes.

Do not nest an anchor within another A tag.

Syntax

<A 
  NAME="
anchorName"
>
...
</A>

Example

<A NAME=section2>
<H2>A Cold Autumn Day</H2></A>
If this anchor is in a file called "nowhere.htm," you could define a link that jumps to the anchor as follows:

<P>Jump to the second section <A HREF="nowhere.htm#section2">
A Cold Autumn Day</A> in the mystery "A man from Nowhere."
The file links.htm shows this example in action in a separate window.

A as link

A hypertext link is a piece of content that the user can click to invoke an action. The most common actions are scrolling to a different place in the current document and opening a new document. A hypertext link can contain text and/or graphics.

To define a hypertext link, use the <A> tag with an HREF attribute to indicate the start of the hypertext link, and use the </A> tag to indicate the end of the link. When the user clicks any content between the <A HREF> and </A> tags, the link is activated.

The value of the HREF attribute must be a URL. If you want the link to open a new document, the value of HREF should be the URL for the destination document. If you want to scroll the current document to a particular place, the value of HREF should be the name of the anchor to which to scroll, preceded by the # sign. If you want to open another document at an anchor, give the URL for the document, followed by #, followed by the name of the anchor.

If you want the destination document or anchor to open in a separate browser window, supply the name of the window as the value of the TARGET attribute. If the named window does not already exist, a new window opens.

The link can also do actions other than opening and scrolling documents. It can send mail messages, point to files located on FTP servers, run any arbitrary JavaScript code, open local files, point to a gopher server, or read news groups. To do any of these actions, you specify an appropriate kind of URL, such as a mailto URL to send a mail message or a news URL to read a news group. See URLS for a discussion of the different kinds of URLs.

Most browsers display hypertext links in a color different from that of the rest of the document so that users can easily identify them. By default, Netscape Navigator displays links in blue, and displays visited links (that is, links that have been clicked) in purple. However, you can specify the default link colors for your document by specifying values for the LINK, VLINK, and ALINK attributes of the BODY tag, as discussed in the section BODY.

You can also define actions that occur when the mouse cursor enters or leaves the region containing the link by specifing onMouseOver and onMouseOut event handlers for the link. Additionally, you can specify an onClick event handler that determines the action to occur when the user clicks a link.

A link that has not been clicked is called an unvisited link. A link that has been clicked is known as a visited or followed link. A link that is in the process of being clicked is an active link.

Syntax

<A
  HREF="
location"
  ONCLICK="
clickJScode"
  ONMOUSEOUT="
outJScode"
  ONMOUSEOVER="
overJScode"
  TARGET="
windowName"
>
...
</A>

HREF="location"

specifies a destination URL for the link. The most common value here is a document name or an anchor. To specify a document to open, provide the URL for the document, either as an absolute or relative URL.

An example of an absolute URL is:

     HREF="http://home.netscape.com/index.html"
An example of a relative URL is:

     HREF="documents/nextdoc.html"
To scroll the current document to an anchor, give the name of the anchor preceded by the pound (#) sign. For example:

     HREF="#anchor1"
To open a different document at an anchor, give the URL for the document, followed by the # sign followed by the name of the anchor. For example:

     HREF="documents/nextdoc.html"
The HREF attribute can also be a URL that sends a message, points to files located on an FTP server, runs arbitrary JavaScript code, opens local files, points to a gopher server, or reads news groups. See URLS for a discussion of the different kinds of URLs.

ONCLICK="clickJScode"

specifies JavaScript code to execute when a user clicks the link. If you supply a value for the ONCLICK attribute, the specified action overrides the default link behavior.For information about JavaScript, see the JavaScript Guide or the JavaScript Reference.

ONMOUSEOUT="outJScode"

specifies JavaScript code to execute when a user moves the mouse cursor out of the link or anchor.

ONMOUSEOVER="overJScode"

specifies JavaScript code to execute when a user moves the mouse pointer over the image or link text. .

TARGET="windowName"

specifies a window in which to show the destination document (if the link's action is to scroll or open a document). If the named window is not already open, a new window with that name opens. Navigator 2.0

Special target values are:

Example

P>You can find all the latest news from Netscape at
<A HREF="http://home.netscape.com/index.html">Netscape's Home Page</A>.
The file links.htm shows this example in action in a separate window. This file also illustrates many additional different uses of links.


[Contents] [Previous] [Next] [Alphabetical Tag List] [Index]

Last Updated: 01/26/98 21:33:44


Copyright © 1998 Netscape Communications Corporation