1. 程式人生 > >js中獲取專案路徑

js中獲取專案路徑

//獲取專案路徑
    var curRequestPath = window.document.location.href;
    console.log("curRequestPath:" + curRequestPath);
    //獲取專案請求路徑 /people/toGetPeopleList.action
    var pathName = window.document.location.pathname;
    console.log("pathName:" + pathName);
    var ipAndPort = curRequestPath.indexOf(pathName); 
    console.log("ipAndPort:" + ipAndPort);
    var localhostPath = curRequestPath.substring(0,ipAndPort);
    console.log("localhostPath:" + localhostPath);
    var projectName = pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    console.log("projectName:" + projectName);
    basePath = localhostPath + projectName;