項目當中會使用到的---獲取主機名

獲取服務器url路徑

舉個栗子

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

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);
                        }
相關文章
相關標籤/搜索