已废弃
该特性已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,但也许会在未来的某个时间停止支持,请尽量不要使用该特性。
link() 方法创建一个 HTML 元素 <a> ,用该字符串作为超链接的显示文本,参数作为指向另一个 URL 的超链接。
语法
str.link(url)
参数
-
url -
任何能够指定
a标签的href属性的字符串;它应当是有效的 URL(相对或绝对),任何&字符将会被转义为&,任何"字符将会被转义为"。
返回值
一个带有一个 HTML 元素 <a> 的字符串。
描述
使用 link 方法创建一个超链接 HTML 片段。返回的字符串可以通过 document.write 或 element.innerHTML 方法添加到文档中。
使用 link 方法创建的链接将会成为 document.links 数组中的元素。查看 document.links。
示例
例子:使用 link
下例显示一个单词 "MDN" 作为超链接,指向 Mozilla Developer Network。
var hotText = 'MDN';
var URL = 'https://developer.mozilla.org/';
document.write('Click to return to ' + hotText.link(URL));
// Click to return to <a href="https://developer.mozilla.org/">MDN</a>
规范
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) String.prototype.link |
Standard | Initial definition. Implemented in JavaScript 1.0. Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers. |
| ECMAScript Latest Draft (ECMA-262) String.prototype.link |
Draft | Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers. |
浏览器兼容性
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
link
|
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Legend
- Full support
- Full support
- Deprecated. Not for use in new websites.
- Deprecated. Not for use in new websites.