分享

js获取网站根路径(站点及虚拟目录),获得网站的根目录或虚拟目录的根地址

 青松卓然 2012-10-30

js获取网站根路径(站点及虚拟目录),获得网站的根目录或虚拟目录的根地址

    //js获取网站根路径(站点及虚拟目录),获得网站的根目录或虚拟目录的根地址     
    function getRootPath(){
        var strFullPath=window.document.location.href;
        var strPath=window.document.location.pathname;
        var pos=strFullPath.indexOf(strPath);
        var prePath=strFullPath.substring(0,pos);
        var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
        return(prePath+postPath);
       }
    */
    
    //js获取网站根路径(站点及虚拟目录),获得网站的根目录或虚拟目录的根地址   
    function getRootPath() {
       var pathName = window.location.pathname.substring(1);
       var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
       //return window.location.protocol + '//' + window.location.host + '/'+ webName + '/';
       return window.location.protocol + '//' + window.location.host + '/'+ webName;
       } 

 

http://blog.csdn.net/vbangle/article/details/5906632 

分类: JavaScript

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多