--- title: HTMLHyperlinkElementUtils.toString() slug: Web/API/HTMLHyperlinkElementUtils/toString tags: - HTMLHyperlinkElementUtils.toString() - URL API translation_of: Web/API/HTMLHyperlinkElementUtils/toString original_slug: Web/API/URLUtils/toString ---

{{ApiRef("URL API")}}

HTMLHyperlinkElementUtils.toString() 方法返回一个包含整个URL的 {{domxref("USVString")}} 。它是{{domxref("HTMLHyperlinkElementUtils.href")}} 的一个只读版本。

句法

string = object.toString();

范例

/*
Let's imagine an
<a id="myAnchor" href="https://developer.mozilla.org/en-US/docs/HTMLHyperlinkElementUtils/toString">
 element is in the document
*/
var anchor = document.getElementById("myAnchor");
var result = anchor.toString();
// Returns: 'https://developer.mozilla.org/en-US/docs/HTMLHyperlinkElementUtils/toString'

规范

Specification Status Comment
{{SpecName('HTML WHATWG', '#htmlhyperlinkelementutils', 'HTMLHyperlinkElementUtils.toString()')}} {{Spec2('HTML WHATWG')}} Initial definition.

浏览器兼容性

{{ CompatibilityTable() }}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatChrome(52)}} {{CompatVersionUnknown}} {{CompatGeckoDesktop("22")}} [2] {{CompatNo}} [1] {{CompatNo}} [1] {{CompatNo}} [1]
Feature Android Webview Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatChrome(52)}} {{CompatChrome(52)}} {{CompatVersionUnknown}} {{CompatGeckoMobile("22")}} [2] {{CompatNo}} [1] {{CompatNo}} [1] {{CompatNo}} [1]

[1] Though not grouped in a single abstract interface, this method is directly available on the interfaces that implement it, if this interface is supported.

[2] From Gecko 22 to Gecko 44, this property was on the URLUtils mixin. It has been moves either on the HTMLHyperlinkElementUtils mixin, or directly on the interface.

也可以看看