js獲取域名:location.origin

域名:

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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章