Visit Mozilla.org

Core JavaScript 1.5 Reference:Global Objects:String:link

From MDC

Non-standard

Contents

[edit] Summary

Creates an HTML hypertext link that requests another URL.

Method of String
Implemented in: JavaScript 1.0, NES2.0

[edit] Syntax

link(hrefAttribute)

[edit] Parameters

hrefAttribute 
Any string that specifies the HREF of the A tag; it should be a valid URL (relative or absolute).

[edit] 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.

[edit] Examples

[edit] 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="http://home.netscape.com">Netscape</A>