js获取项目根路径

 

废话不多说,直接上代码!

 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         //获取带"/"的项目名,如:/uimcardprj
11         var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
12         return (localhostPaht + projectName);
13 }

 

posted @ 2017-09-28 16:17  oldmonk  阅读(1784)  评论(0编辑  收藏  举报
Fork me on GitHub