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

posted @ 2016-12-26 11:41  Garnett_Boy  阅读(587)  评论(0编辑  收藏  举报