url路径解析
对于一个url,例如:http://www.example.com:8888/search?keyword=test&page=1#a ,其包含的部分有:
1 协议(protocol)”http:”,可以通过window.location.protocol属性获取
2 域名:(hostname)”www.example.com”,可以通过window.location.hostname属性和window.location.host获取
3 路由:(route) “/search”,可以通过window.location.pathname属性获取
4 查询串:(query) “keyword=test&page=1”,可以通过window.location.search属性获取
5 hash:(hash) “#a”,可以通过window.location.hash属性获取