美文网首页
WebAPI:URL

WebAPI:URL

作者: 春暖花已开 | 来源:发表于2022-03-15 01:24 被阅读0次
const url = new URL('https://lynn:123456@baidu.com:8080/news/cn?type=political&size=100#/hash')

console.log(url.username) //lynn
console.log(url.password) // 123456
console.log(url.protocol) //scheme + ':'
console.log(url.host) // baidu.com:8080
console.log(url.hostname) // baidu.com
console.log(url.port) // 8080
console.log(url.origin) // https://baidu.com:8080
console.log(url.pathname) // /news/cn
console.log(url.search) // ?type=political&size=100
console.log(url.hash) // #/hash

如果端口号是scheme的默认端口,那么在host、origin、port里都不会显示出来。可以使用 new URL('https://lynn:123456@baidu.com:443/news/cn?type=political&size=100#/hash') 来验证。


参考

WebAPI:URL

相关文章

网友评论

      本文标题:WebAPI:URL

      本文链接:https://www.haomeiwen.com/subject/nlyedrtx.html