详细解析BOM中Location对象
Location对象包含有关当前URL的信息。
// href 返回完整的URL
console.log(location.href);
// host 返回一个URL的主机名和端口
console.log(location.host);
// hostname 返回URL的主机名
console.log(location.hostname);
// port 返回一个URL服务器使用的端口号
console.log(location.port);
// origin 源 返回URL的协议,主机名和端口号。
console.log(location.origin);
// pathname 返回的URL路径名。
console.log(location.pathname);
// protocol 返回一个URL协议
console.log(location.protocol);
// search 返回一个URL的查询部分 ?后面的内容(包含?)
console.log(location.search);
// hash 返回一个URL的锚部分 #后面的内容(包含#)
console.log(location.hash);
// https: //item.taobao.com/item.htm?id=619020982176&ali_refid=a3_430673_1006:1123561332:N:rvrUsViJQFAUL6P%2BVfgyjg%3D%3D:674960c3f0e5ecdc7c05fc9a71c8b920&ali_trackid=1_674960c3f0e5ecdc7c05fc9a71c8b920&spm=a2e15.8261149.07626516002.1
// https: //item.taobao.com/item.htm?id=617893286382&ali_refid=a3_430673_1006:1124382759:N:emtiAWsF8%2Bzhhxaiwzc0Aw%3D%3D:245061a3dde641709e1761ad374ca601&ali_trackid=1_245061a3dde641709e1761ad374ca601&spm=a2e15.8261149.07626516002.2
视频讲解链接:
https://www.bilibili.com/video/BV1NA411B7wE/