JavaScript: The Definitive Guide
25.195. Link: a hyperlink or anchor in an HTML document
DOM Level 0: Node |
Property | Attribute | Description |
|---|---|---|
String accessKey | accesskey | Keyboard shortcut |
String charset | charset | Encoding of the destination document |
String coords | coords | For <area> tags |
String hreflang | hreflang | Language of the linked document |
String name | name | Anchor name; see Anchor |
String rel | rel | Link type |
String rev | rev | Reverse link type |
String shape | shape | For <area> tags |
long tabIndex | tabindex | Link's position in tabbing order |
String target | target | Name of the frame or window in which the destination document is to be displayed |
String type | type | Content type of the destination document |
25.195.2. Methods
blur( )
Takes keyboard focus away from the link.
focus( )
Scrolls the document so the link is visible and gives keyboard focus to the link.
25.195.3. Event Handlers
The Link object has special behavior for three event handlers:
onclick
Invoked when the user clicks on the link.
onmouseout
Invoked when the user moves the mouse off the link.
onmouseover
Invoked when the user moves the mouse over the link.
25.195.4. HTML Syntax
A Link object is created with standard <a> and </a> tags. The href attribute is required for all Link objects. If the name attribute is also specified, an Anchor object is also created:
<a href="url" // The destination of the link [ name="anchor_tag" ] // Creates an Anchor object [ target="window_name" ] // Where the new document should be displayed [ onclick="handler" ] // Invoked when link is clicked [ onmouseover="handler" ] // Invoked when mouse is over link [ onmouseout="handler" ] // Invoked when mouse leaves link >link text or image // The visible part of the link </a>
25.195.5. Description
A Link object represents a hyperlink in a document. Links are usually created with <a> tags that have an href attribute defined, but they may also be created with <area> tags inside a client-side image map. When an <a> tag has a name attribute instead of an href attribute, it defines a named position in a document and is represented by an Anchor object instead of a Link object. See Anchor for details.
All links in a document (whether created with <a> or <area> tags) are represented by Link objects in the links[] array of the Document object.
The destination of a hypertext link is a URL, of course, and many of the properties of the Link object specify the contents of that URL. In this way, the Link object is similar to the Location object, which also has a full set of URL properties.
25.195.6. Example
// Get the URL of the first hyperlink in the document var url = document.links[0].href;
25.195.7. See Also
Anchor, Location
Категории