Location: toString() 方法

Baseline 已广泛支持

此功能已相当成熟,可在多种设备和浏览器版本上使用。自 ⁨2016 年 7 月⁩起,所有浏览器均已支持此功能。

toString() 方法是 Location 接口的字符串化方法,它返回一个包含完整 URL 的字符串。它是 Location.href 的只读版本。

语法

js
toString()

参数

无。

返回值

一个表示对象 URL 的字符串。

示例

js
// Let's imagine this code is executed on https://example.com/path?search#hash
const result = window.location.toString(); // Returns: 'https://example.com/path?search#hash'

规范

规范
HTML
# dom-location-href-dev

浏览器兼容性