(本例)URL:http://www.itnotes.cc:80/example.html?ver=1.0&id=1#hash

用js获得其中的各个部分

1、window.location.href
整个URl字符串(在浏览器中就是完整的地址栏)
本例返回值:
http://www.itnotes.cc:80/example.html?ver=1.0&id=1#hash

2、window.location.protocol
URL的协议部分
本例返回值:http:

3、window.location.host
URL的主机部分
本例返回值:www.itnotes.cc

4、window.location.port
URL的端口部分
如果采用默认的80端口(即使添加了:80),那么返回值并不是默认的80而是空字符
本例返回值:””

5、window.location.pathname
URL的路径部分(就是文件地址)
本例返回值:/example.html

6、window.location.search
参数部分
本例返回值:?ver=1.0&id=1

7、window.location.hash
锚点部分
本例返回值:#hash