接下来以http://www.myurl.com:8866/test?id=123&username=xxx作为栗子,介绍一下location的常用属性:
1,window.location.href (当前 URL)
结果 : http://www.myurl.com:8866/test在这里插入代码片?id=123&username=xxx
2,window.location.protocol (协议)
结果 : http:
3,window.location.host ( 域名 和 端口 )在这里插入代码片
结果 : www.myurl.com:8866
4,window.location.hostname ( 域名 )
结果 : www.myurl.com在这里插入代码片
5,window.location.port ( 端口 )
结果 : 8866
6,window.location.pathname ( 路径部分 )
结果 : /test
7,window.location.search (请求的参数)
结果 : ?id=123&username=xxx
8,window.location.origin ('?'前边的URL)
结果 : http://www.myurl.com:8866