javascript get the resource path + project name in the browser address column

<script type="text/javascript">

function getRootPath_web() {
       //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp
       var curWwwPath = window.document.location.href;
       //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp
       var pathName = window.document.location.pathname;
       var pos = curWwwPath.indexOf(pathName);
       //获取主机地址,如: http://localhost:8083
       var localhostPaht = curWwwPath.substring(0, pos);
       //获取带"/"的项目名,如:/uimcardprj
       var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
       return (localhostPaht + projectName);
}

var hisUrl=getRootPath_web(); 

</script>

Searched on the Internet, the IP of the resource after nginx proxy may change, so do not generate the resource path through the java program

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325363294&siteId=291194637