现在的位置: 首页 > 综合 > 正文

js 获取 项目 根路径 JavaScript

2013年08月17日 ⁄ 综合 ⁄ 共 590字 ⁄ 字号 评论关闭

 

/**
 * 获取项目根路径1
 * @return {RootPath}
 * @author 李海云
 */
function getRootPath1(){
	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);
}
/**
 * 获取项目根路径2
 * @return {RootPath}
 * @author 李海云
 */
function getRootPath2() 
{ 
	 var pathName = window.location.pathname.substring(1);
	 var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
	 return window.location.protocol + '//' + window.location.host + '/'+ webName + '/'; 
} 

抱歉!评论已关闭.