js擷取系統的根路徑實現介紹

來源:互聯網
上載者:User

複製代碼 代碼如下:
function getBasePath(){
var obj=window.location;
var contextPath=obj.pathname.split("/")[1];
var basePath=obj.protocol+"//"+obj.host+"/"+contextPath;
return basePath;
}

javascript對象包含

1.window javascript的頂層對象

2.navigator 用戶端瀏覽器的資訊

3.screen 用戶端顯示屏的資訊

4.history 瀏覽器視窗訪問過的url資訊

5.location 當前url資訊

其中location對象包含

比如有這樣一個html地址 http://localhost:8080/huyao_soccer/huyao/tag/myplugin.jsp

1.hash

2.host 主機名稱和當前url的連接埠號碼 返回:localhost:8080

3.hostname 主機名稱 返回:localhost

4.href 完整的url 返回:http://localhost:8080/huyao_soccer/huyao/tag/myplugin.jsp

5.pathname 返回當前url的路徑部分 返回:/huyao_soccer/huyao/tag/myplugin.jsp

6.port 連接埠號碼 返回:8080

7.protocol 協議 返回: http:

8.search 從?開始的url部門(查詢部分)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.