Revision 87813 of String.prototype.link()

  • Revision slug: JavaScript/Reference/Global_Objects/String/link
  • Revision title: link
  • Revision id: 87813
  • Created:
  • Creator: evilpie
  • Is current revision? No
  • Comment 4 words added, 5 words removed

Revision Content

{{ Non-standard_header() }}

Creates an HTML hypertext link that requests another URL.

Method of String
Implemented in 1.0
ECMAScript Edition none

Syntax

link(hrefAttribute)

Parameters

hrefAttribute 
Any string that specifies the HREF of the A tag; 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 {{ Domxref("document.write") }} or {{ Domxref("element.innerHTML") }}.

Links created with the link method become elements in the links array of the document object. See {{ Domxref("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="http://home.netscape.com">Netscape</A>


{{ languages( { "es": "es/Referencia_de_JavaScript_1.5/Objetos_globales/String/link", "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/String/link", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/String/link" } ) }}

Revision Source

<p>
{{ Non-standard_header() }}
</p>
<p>Creates an <a class="external" href="http://www.w3.org/TR/html401/struct/links.html#adef-href" rel="external nofollow" target="_blank" title="http://www.w3.org/TR/html401/struct/links.html#adef-href">HTML hypertext link</a> that requests another URL.
</p>
<table class="standard-table"> <thead> <tr> <th class="header" colspan="2">Method of <a href="/en/JavaScript/Reference/Global_Objects/String"><code>String</code></a></th> </tr> </thead> <tbody> <tr> <td>Implemented in</td> <td>1.0</td> </tr> <tr> <td>ECMAScript Edition</td> <td>none</td> </tr> </tbody>
</table> <h3 name="Syntax"> Syntax </h3>
<p><code>
link(<i>hrefAttribute</i>)
</code>
</p>
<h3 name="Parameters"> Parameters </h3>
<dl><dt> <code>hrefAttribute</code> </dt><dd> Any string that specifies the <code>HREF</code> of the <code>A</code> tag; it should be a valid URL (relative or absolute).
</dd></dl>
<h3 name="Description"> Description </h3>
<p>Use the <code>link</code> method to create an HTML snippet for a hypertext link. The returned string can then be added to the document via {{ Domxref("document.write") }} or {{ Domxref("element.innerHTML") }}.
</p><p>Links created with the <code>link</code> method become elements in the <code>links</code> array of the <code>document</code> object. See {{ Domxref("document.links") }}.
</p>
<h3 name="Examples"> Examples </h3>
<h4 name="Example:_Using_link"> Example: Using <code>link</code> </h4>
<p>The following example displays the word "Netscape" as a hypertext link that returns the user to the Netscape home page:
</p>
<pre>var hotText="Netscape"
var URL="http://home.netscape.com"

document.write("Click to return to " + hotText.link(URL))
</pre>
<p>This example produces the same output as the following HTML:
</p>
<pre>Click to return to &lt;A HREF="http://home.netscape.com"&gt;Netscape&lt;/A&gt;
</pre>
<p><br>
</p>
<div class="noinclude">
</div>
{{ languages( { "es": "es/Referencia_de_JavaScript_1.5/Objetos_globales/String/link", "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/String/link", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/String/link" } ) }}
Revert to this revision