jquery自動獲取項目url路徑


//很多時候我們需要使用當前項目路徑,但是如果把項目路徑寫死,會帶來很多不便,此時就需要自動獲取項目路徑。
//我們可以根據jquery來進行自動獲取項目路徑,獲取方法如下
function
getRootPath() { // 1、獲取當前全路徑,如: http://localhost:8080/springmvc/page/frame/test.html var curWwwPath = window.location.href; // 獲取當前相對路徑: /springmvc/page/frame/test.html var pathName = window.location.pathname; // 獲取主機地址,如: http://localhost:8080 var local = curWwwPath.substring(0,curWwwPath.indexOf(pathName));
//
獲取帶"/"的項目名,如:/springmvc
var
projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
var
rootPath = local + projectName;
return
rootPath;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM