Location: toString()

toString()Location接口的 stringifier 方法返回包含整个 URL 的USVString。它是Location.href的只读版本。

句法

string = object.toString();

例子

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

规范

Specification
HTML Standard
# dom-location-href-dev

浏览器兼容性

BCD tables only load in the browser