【js获取项目根路径】
2017-10-20 09:32
204 查看
js获取项目根路径,如: http://localhost:8083/uimcardprj
function getRootPath() {
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);
}
function getRootPath() {
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);
}