js 获取项目根路径

function getRootPath() {
    var pathName = window.location.pathname.substring(1);
    var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
    if (webName == '') {
        return window.location.protocol + '//' + window.location.host + '/';
    } else {
        return window.location.protocol + '//' + window.location.host + '/' + webName + '/';
    }
}

猜你喜欢

转载自blog.csdn.net/ZouChengli/article/details/79969714
今日推荐