项目当中会使用到的---获取主机名

获取服务器url路径

举个栗子

http://localhost:8080/xhs/html/error_type_manger.html

 getRoot: function () {
    var curWwwPath = window.document.location.href;          //整个url地址 http://localhost:8080/xhs/html/error_type_manger.html
   var pathName = window.document.location.pathname;  //     文件路径名 /xhs/html/error_type_manger.html
   var pos = curWwwPath.indexOf(pathName);  //路径名开始的索引值 
   var localhostPath = curWwwPath.substring(0, pos);// 获得主机名地址 http://localhost:8080
   var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1); // 获得工程目录文件 /xhs
  return (localhostPath + projectName);
                        }
posted @ 2017-04-02 11:10  Queen-英  阅读(275)  评论(0编辑  收藏  举报