例:http://127.0.0.1:8080/index.html?userName=zhangsan&passWord=123456
1、获取URL 的路径部分(文件地址)
window.location.pathname
(本例中返回 index.html)
2、获取URL 完整地址(地址栏的整个地址)
window.location.href
(本例中返回 http://127.0.0.1:8080/index.html?userName=zhangsan&passWord=123456)
3、获取端口号
window.location.port
(本例中返回 8080)
4、获取URL 的协议部分
window.location.protocol
(本例中返回 http: )
5、获取主机名和端口号
window.location.host
(本例中返回 127.0.0.1:8080)
6、获取参数部分(?后面的参数)
window.location.search
(本例中返回 ?userName=zhangsan&passWord=123456)