window.location对象详解

 

window.location.href(当前URL)

结果如下:
http://www.myurl.com:8866/test?id=123&username=xxx

window.location.protocol(协议)

结果如下:
http:

window.location.host(域名 + 端口)

结果如下:
www.myurl.com:8866

window.location.hostname(域名)

结果如下:
www.myurl.com

window.location.port(端口)

结果如下:
8866

window.location.pathname(路径部分)

结果如下:
/test

window.location.search(请求的参数)

结果如下:
?id=123&username=xxx

window.location.origin('?'前边的URL)

结果如下:
http://www.myurl.com:8866

原文地址:https://www.cnblogs.com/lxsunny/p/11979608.html