JS获取项目根目录

function getRootPath(){
//获取当前网址,如: http://localhost:8088/test/test.jsp
var curPath=window.document.location.href;
//获取主机地址之后的目录,如: test/test.jsp
var pathName=window.document.location.pathname;
var pos=curPath.indexOf(pathName);
//获取主机地址,如: http://localhost:8088
var localhostPaht=curPath.substring(0,pos);
//获取带"/"的项目名,如:/test
var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
return(localhostPaht+projectName);
}
上一篇:Javascript 异步编程的4种方法详解


下一篇:UVa753/POJ1087_A Plug for UNIX(网络流最大流)(小白书图论专题)