mozilla

Revision 87811 of String.prototype.link()

  • Revision slug: JavaScript/Reference/Global_Objects/String/link
  • Revision title: link
  • Revision id: 87811
  • Created:
  • Creator: Sevenspade
  • Is current revision? No
  • Comment tagging as non-standard

Revision Content

{{wiki.template('Non-standard_header')}}

Summary

Creates an HTML hypertext link that requests another URL.

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

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 {{template.Domxref("document.write")}} or {{template.Domxref("element.innerHTML")}}.

Links created with the link method become elements in the links array of the document object. See {{template.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>
{{ wiki.languages( { "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>
{{wiki.template('Non-standard_header')}}
</p>
<h3 name="Summary"> Summary </h3>
<p>Creates an <a class="external" href="http://www.w3.org/TR/html401/struct/links.html#adef-href">HTML hypertext link</a> that requests another URL.
</p>
<table class="fullwidth-table">
<tbody><tr>
<td class="header" colspan="2">Method of <a href="en/Core_JavaScript_1.5_Reference/Objects/String">String</a></td>
</tr>
<tr>
<td>Implemented in:</td>
<td>JavaScript 1.0, NES2.0</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 {{template.Domxref("document.write")}} or {{template.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 {{template.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>
<div class="noinclude">
</div>
{{ wiki.languages( { "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