1 //js获取项目根路径,如: http://localhost:8083/uimcardprj 2 function getRootPath(){ 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 //获取带"/"的项目名,如:/uimcardprj 11 var projectName=pathName.substring(0,pathName.substr(1).indexOf(‘/‘)+1); 12 return(localhostPaht+projectName); 13 }
时间: 2024-11-09 02:29:18