javaScript 获取主机地址,项目名等

//获取当前网址 
var curWwwPath=window.document.location.href;
alert(curWwwPath);  //http://localhost:8080/Test/index.jsp 

//获取主机地址之后的目录
var pathName=window.document.location.pathname;
alert(pathName); //  /Test/index.jsp 

//获取主机地址
var pos=curWwwPath.indexOf(pathName);
var localhostPaht=curWwwPath.substring(0,pos);
alert(localhostPaht);//   http://localhost:8080 
//获取带"/"的项目名,
var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
alert(projectName);//  /Test

原文地址:https://www.cnblogs.com/Garnett-Boy/p/6221792.html