URL.toJSON()

URL接口的 toJSON() 方法返回一个USVString,其中包含一个序列化的URL版本,尽管在实践中它似乎与URL.toString()有相同的效果。

Note: 此特性在 Web Worker 中可用。

语法

const href = url.toJSON()

返回值

一个 USVString.

例子

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

说明

说明 状态 评论
URL
toJSON()
Living Standard 初步定义.

浏览器兼容

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
toJSONChrome Full support 71Edge Full support 17Firefox Full support 54IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 71Chrome Android Full support 71Firefox Android Full support 54Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 10.0

Legend

Full support  
Full support
No support  
No support