You are here:  NetStrider » Tutorials » HTMLRef » Commands » A (Anchor) «

HTML Reference Guide

Author: Randy D. Ralph.   In place March 1, 1999.   Copyright © 1999 NetStrider.   Presented as a public service.

BACK <A> Command next

The anchor command takes two basic forms depending on the use of one of these two principal attributes: 
  1. href - used to define a Hypertext Reference Link.

  2. name - used to define a Hypertext Name Anchor.

1.  A Hypertext Reference Link:

Command Syntax:

<A href="URL" other command parameters> link text or object </A>

Command Parameters:
href="URL"

Defines the URL, or Internet address, associated with the link.  When the link is followed (by mouse click or other means) the browser will attempt to locate and display the code available at the specified URL.

See the information on protocol type for URLs below.

target="target name"
  • Defines the target of the code specified by the URL.  This can be a named frame within a framed document or it can be one of several standard reserved values (below) that govern how HTML code will be handled by the browser in the viewing window.

  • The name supplied must match either one of the standard reserved target names (below) or one of the the preassigned frame names in a framed document.
title="title text"

Defines some title text which is displayed by the browser in the information bar at the bottom of the screen when a user moves the mouse pointer over the link. By default the URL to which the link points is displayed in this space.

See also the onMouseOver event capture parameter below.

There are several other advanced command attributes and parameters which can be used with the anchor command.  Most beginning HTML authors will only find the target and title parameters (defined above) useful.  The others are:

  • methods=
  • rev=
  • rel=
  • urn=

See an advanced HTML reference guide for information on these command parameters.

Event Capture Parameters:

onClick executes a function associated with the link when a mouse click on the link is detected
onMouseOut executes a function associated with the link when the mouse cursor moves away from the link
onMouseOver executes a function associated with the link when the mouse cursor moves over the link

Standard Reserved Target Names:

_blank

Creates a new browser window and displays the document specified by the URL within it.

_self

Displays the document specified by the URL over itself in the same browser window.

_parent

Displays the document specified by the URL over the document parent.  If there is no parent document then it replaces the contents of the browser window.

_top

Clears the current browser display and displays the document specified by the URL at the top level.  If already at the top then the codument simply replaces the content of the browser window.

HTTP Protocols for use in URLs:

file:/// - directs the link to and opens local file.

ftp:// - file transfer protocol - directs the link to an FTP file server.

gopher:// - gopher protocol - directs the link to a gopher file server.

http:// - hypertext transfer protocol - directs the link to a WWW file server.

mailto: - browser mail link - opens a mail window and directs mail to the address specified.

news: - newsgroup - connects to the default nntp server and opens the named newsgroup.

newsrc: - a specific newsrc file - generally opens a local news source file.

nntp:// - network news transfer protocol - connects to an nntp news file server other than the default.

telnet:// - asynchronous telecommunications via telnet - connects to the host computer specified.

wais:// - wide area information server protocol - directs the link to a WAIS index server.

Examples: | Text Links | Graphical Links | Specially Formatted Links |
 
Text Links:

<A HREF="http://www.iconbazaar.com/">IconBAZAAR</A>

This would direct the user to the URL http://www.iconbazaar.com/ when the link text IconBAZAAR is clicked on.  When the user's mouse moves over the link text the pointer changes from an arrow arrow to a pointing hand hand to indicate that this link can be followed.

<A HREF="toc.html" target="toc">Table of Contents</A>

This would load the HTML document toc.html into a defined frame named toc in the currently displayed browser window when the link text Table of Contents is clicked on.

<A HREF="http://www.ibm.com/" target="_top">IBM</A>

This would load the HTML document at URL http://www.ibm.com into the currently displayed browser window when the link text IBM is clicked on and would completely replace any existing content, including any currently displayed frames.
 

Graphical Links:

<A HREF="http://www.iconbazaar.com/"><img src="images/bazicon1.gif"
height=20 width=120>
</A>

Would produce the graphical link shown below:

Note that the object link is surrounded by a blue border by the browser to indicate that it is, in fact, a link.  This can be eliminated by using the border=0 parameter in the inline image command that sets the graphic as follows:

<A HREF="http://www.iconbazaar.com/"><img src="images/bazicon1.gif"
height=20 width=120 border=0>
</A>

Would produce the borderless graphical link shown below:


 

Specially Formatted Links:

file:///

<A HREF="file:///c|/HTML/examples/example_1.html">example 1</A>

The file:/// protocol requires a proper path to a local file on the user's machine or on a local area network.  The example above shows the correct form of the path statement for the DOS file path: C:\HTML\examples\example1.html.  Note that the URL uses forward slashes / not the standard DOS backward slashes \ and that a vertical bar | replaces the colon : in the drive letter designation.  In some, but not all disk operating systems, there may also be case sensitivity in the path.


ftp://

<A HREF="ftp://ender@maggie.blimpo.com">ENDER ACCOUNT</A>

If the FTP protocol is used in a link access is anonymous and the user is directed to a public directory unless a user name followed by the @ sign is used.  Current high-end browsers will permit a password-protected login to a specified user's file space as in the example above.  User ender would be prompted for a password.  A successful login would permit access to user ender's directory structure and file space via the browser.


mailto:

<A HREF="mailto:Randy_Ralph@uncg.edu?subject=HTML Feedback">Feedback</A>

Generally the mailto:userid@someplace.com protocol only requires a valid SMTP email address in order to work properly in most browsers.  The browser opens an email dialog box and sends the email to the address specified in the URL if the appropriate account and server information is configured.  Most high-end browsers now also support the use of the ?subject= parameter which permits the subject line of the email to be specified within the URL as in the example above.


news:

<A HREF="news:alt.sci-fi.movies">Sci-Fi News</A>

The news: protocol only requires the name of a recognized newsgroup.  The browser must be configured for an nntp news file server, the user must have access to the server and the server must have the news feed for the newsgroup specified in the URL.
 


2.  A Hypertext Name Anchor:

Command Syntax:

<A name="label name"> </A>

Examples: 
Creating a Name Anchor:

<A name="top"></A>

This would define a location in the current HTML document labeled top precisely at the point in the document code where the command is placed.  This name anchor can then be referenced by any hypertext reference link whether internal or external to the document in which the name anchor is placed.  Note that it is not necessary to place any text within the name anchor.  Text which is placed within a name anchor is not formatted differently from normal text.

All of the internal links within this document have been created in this manner.

Referencing a Name Anchor:

<A href="anchor.html#top">TOP</A>

The name of the file you are currently viewing is anchor.html.  You can easily verify this by looking in the location bar of your browser.  The link above will reload the file and begin display at the named location top.  Since display begins precisely at the named anchor location in the referenced document it is generally good practice to place a name anchor slightly above the point in the document where the browser should begin display.
 

Return to Section A:D


Return to the List of Commands.
Author: Randy D. Ralph.  In place March 1, 1999.  Copyright © 1999 NetStrider.  World Rights reserved.




Hosted by uCoz