HTML URL地址解析
通过JavaScript的location对象,可获取URL中的协议、主机名、端口、锚点、查询参数等信息。
示例
URL:http://www.akmsg.com/WebDemo/URLParsing.html#top?username=admin&pwd=123456
解析结果:
代码console.log(
'location.hash :' + location.hash + '\r\n' +
'location.host :' + location.host + '\r\n' +
'location.hostname :' + location.hostname + '\r\n' +
'location.href :' + location.href + '\r\n' +
'location.pathname :' + location.pathname + '\r\n' +
'location.port :' + location.port + '\r\n' +
'location.protocol :' + location.protocol + '\r\n' +
'location.hash :' + location.hash + '\r\n' +
'location.search :' + location.search + '\r\n' +
'location.origin :' + location.origin
)
在线示例