Home >Web Front-end >JS Tutorial >HTML URL address parsing
HTML URL address parsing
Through the location object of JavaScript, you can obtain the protocol, host name, port, anchor point, query parameters and other information in the URL.
Example
URL: http://www.akmsg.com/WebDemo/URLParsing.html#top?username=admin&pwd=123456
Parse results:
Code
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 )
Online example
Address: http://www.akmsg.com/WebDemo/URLParsing.html