//1、使用 window.locaion.href 获得项目的根路径
var curWwwPath = window.document.location.href;
//2、获得主机地址之后 的目录
var pathname= window.document.location.pathname;
var pos = curWwwPath.indexOf(pathname);
//3、获得主机地址
var localhostPath = curWwwPath .substring(0,pos);
转载于:https://my.oschina.net/chendongj/blog/1606107