1 //获取项目根路径 2 function getRootPath_web() { 3 //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp 4 var curWwwPath = window.document.location.href; 5 //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp 6 var pathName = window.document.location.pathname; 7 var pos = curWwwPath.indexOf(pathName); 8 //获取主机地址,如: http://localhost:8083 9 var localhostPaht = curWwwPath.substring(0, pos);10 //获取带"/"的项目名,如:/uimcardprj11 var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);12 return (localhostPaht + projectName);13 }