--- title: 'Location: toString()' slug: Web/API/Location/toString translation_of: Web/API/Location/toString ---
{{ApiRef("Location")}}
toString()
{{domxref("Location")}}接口的stringifier方法返回包含整个URL的{{domxref("USVString")}}}。它是{{domxref("Location.href")}}的只读版本。
string = object.toString();
// Let's imagine an <a id="myAnchor" href="https://developer.mozilla.org/en-US/docs/Location/toString"> element is in the document var anchor = document.getElementById("myAnchor"); var result = anchor.toString(); // Returns: 'https://developer.mozilla.org/en-US/docs/Location/toString'
规范 | 状态 | 评论 |
---|---|---|
{{SpecName("HTML WHATWG","#dom-location-href")}} | {{Spec2("HTML WHATWG")}} |
{{Compat("api.Location.toString")}}