domain name:
location.origin
The main commonly used codes:
Host, domain name:
location.host
Anchor:
location.hash
domain name:
location.origin
Request path:
location.pathname
port:
location.port
protocol:
location.protocol
Request parameters in url:
location.search
The technique of parsing the root domain name of a URL in javascript (if you don't do this, it seems that you can only write regular expressions to get the root domain name):
var a=document.createElement('a');
a.href='http://music.baidu.com/search?fr=ps&key=12306&ie=utf-8&ie=utf-8';
alert(a.host);
Demo presentation:
<a href='http://baidu.com' οnclick='alert(this.host+" | "+this.origin)'>百度</a>