牛骨文教育服务平台(让学习变的简单)
博文笔记

JS 获取网站根目录 域名+站名

创建时间:2012-05-28 投稿人: 浏览次数:1152

//获取根路径
function getBasePath() {
    var curWwwPath = window.document.location.href;
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    var localhostPaht = curWwwPath.substring(0, pos);
    var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
    return (localhostPaht + projectName);
}

 

注:需要在VS或者 IIS中测试

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。