javascript获取项目根目录带项目名_


javascript获取项目根目录带项目名

//获取当前网址,如: http://localhost:8080/chenThree/jspPage/pages/projectImplementation.html
var curWwwPath=window.document.location.href; 									
//获取主机地址之后的目录如:/chenThree/jspPage/pages/projectImplementation.html 
var pathName=window.document.location.pathname; 
var pos=curWwwPath.indexOf(pathName); 									
//获取主机地址,如: http://localhost:8080/chenThree
var localhostPaht=curWwwPath.substring(0,pos); 									
//获取带"/"的项目名,如:/chenThree
var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1); 

本文转自 https://blog.csdn.net/hello_mr_anan/article/details/78769616?spm=1001.2014.3001.5501,如有侵权,请联系删除。