URL:toJSON() 方法

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

备注: 此特性在 Web Worker 中可用。

URL 接口的 toJSON() 方法返回一个包含 URL 序列化版本的字符串,但实际上它似乎与 URL.toString() 的效果相同。

语法

js
toJSON()

参数

无。

返回值

字符串。

示例

js
const url = new URL(
  "https://developer.mozilla.org/zh-CN/docs/Web/API/URL/toString",
);
url.toJSON(); // 应以字符串形式返回 URL

规范

Specification
URL
# dom-url-tojson

浏览器兼容性

参见