Table of contents
- 1. Summary
- 2. Syntax
- 3. Parameters
- 4. Description
- 5. Examples
- 5.1. Example: Using link
Summary
Creates an HTML hypertext link that requests another URL.
Method of String | |
|---|---|
| Implemented in | JavaScript 1.0 |
| ECMAScript Edition | none |
Syntax
link(hrefAttribute)
Parameters
-
hrefAttribute - Any string that specifies the
HREFof theAtag; it should be a valid URL (relative or absolute).
Description
Use the link method to create an HTML snippet for a hypertext link. The returned string can then be added to the document via
document.write or
element.innerHTML.
Links created with the link method become elements in the links array of the document object. See
document.links.
Examples
Example: Using link
The following example displays the word "Netscape" as a hypertext link that returns the user to the Netscape home page:
var hotText="Netscape"
var URL="http://home.netscape.com"
document.write("Click to return to " + hotText.link(URL))
This example produces the same output as the following HTML:
Click to return to <A HREF=/old?u=https%3A%2F%2Fdeveloper.mozilla.org%2Fen%2FJavaScript%2FReference%2FGlobal_Objects%2FString%2F%26quot%3Bhttp%3A%2Fhome.netscape.com%26quot%3B%26gt%3BNetscape%26lt%3B%2FA%26gt&y=1999