首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

[转]JS取得当前项目的根路径

2012-10-07 
[转]JS获得当前项目的根路径来源:?http://zghbwjl.blog.163.com/blog/static/1203366722010714103150595/

[转]JS获得当前项目的根路径

来源:?http://zghbwjl.blog.163.com/blog/static/1203366722010714103150595/
两种方法,其实一样,第一种:

<script>
function getRootPath(){
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);
}

alert (getRootPath());
</script>

第二种:

<script type="text/javascript">
function getRootPath()
{
var pathName = window.location.pathname.substring(1);
var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
return window.location.protocol + '//' + window.location.host + '/'+ webName + '/';
}
alert (getRootPath());
</script>?

热点排行
Bad Request.