1、获取当前页面完整的url:
let url = location.href;
console.log(url) // --angel的博客_CSDN博客-领域博主
2、 获取当前页面的域名:
let host1 = window.location.host;
let host2 = document.domain;
let host3 = location.hostname;
console.log(host1, host2, host3) // mp.csdn.net
3、获取端口号:
let port = location.port;
console.log(port)
4、获取协议:
let protocol =location.protocol;
console.log(protocol) // https:
5、获取页面路径:
let pathName = location.pathname;
console.log(pathName) // /mp_blog/manage/article
6、获取href属性?后面的内容:
let str =location.search;
let search =a.substr(1);
console.log(search); // spm=1001.2100.3001.5448
7、获取=后面的内容:
let href = location.href;
let hrefcontent = href.substring(href.lastIndexOf('=')+1);
console.log(hrefcontent) // 1001.2100.3001.5448