JS文件中获取contextPath的方法

function getContextPath() {
    var pathName = document.location.pathname;
    var index = pathName.substr(1).indexOf("/");
    var result = pathName.substr(0,index+1);
    return result;
}

原文地址:https://www.cnblogs.com/thiaoqueen/p/6835643.html