JavaScript获取http,http://请求协议头,域名,端口,url

window.location.protocol 获取http,http://请求协议头
window.location.host 获取域名并带端口 xxx.com 如果有端口就是 xxx.com:8080
window.location.hostname; 获取域名: xxx.com
window.location.href; 获取整个url地址:http://xxx.com/xxx.html
window.location.pathname; 获取域名后面请求路径url: /xxx/xxx.html
window.location.port 获取端口比如 8080

原文地址:https://www.cnblogs.com/javakfz/p/13938218.html