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.

备注: 此特性在 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

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
toJSON

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Has more compatibility info.

参见