WebAPI:URL

const url = new URL('https://lynn:[email protected]: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:[email protected]:443/news/cn?type=political&size=100#/hash') 来验证。


参考

WebAPI:URL

你可能感兴趣的:(WebAPI:URL)