域名:
location.origin
主要常用的代碼:
主機、域名:
location.host
錨點:
location.hash
域名:
location.origin
請求路徑:
location.pathname
端口:
location.port
協議:
location.protocol
url中請求參數:
location.search
javascript中解析一個url的根域名的技巧(不這樣做的話,貌似就是隻能寫正則表達式去取得根域名了):
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演示:
<a href='http://baidu.com' οnclick='alert(this.host+" | "+this.origin)'>百度</a>