截取地址栏的地址
window.location.href 浏览器的地址
window.location.search ?和参数
encodeURI()对url进行编码,就是对空格进行编码,其余的部分没有发生变化
let url = 'https://www.baidu.com/13572078512?token=123 &name= alice'
console.log(encodeURI(url)) https://www.baidu.com/13572078512?token=123%20&name=%20alice
encodeURIComponent()对url进行编码,就是对url中的特殊符号 :?//=&$等特殊符号进行编码
let url = 'https://www.baidu.com/13572078512?token=123&name=alice'
encodeURIComponent(url) https%3A%2F%2Fwww.baidu.com%2F13572078512%3Ftoken%3D123%26name%3Dalice