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);
}
var webpath=getRootPath(); //webpath就是目录路径变量
JavaScript获取网站根目录地址
最新推荐文章于 2023-04-25 13:28:45 发布
本文介绍了一种通过JavaScript实现的获取当前网站根路径的方法。该方法利用window对象的location属性来确定URL中的路径部分,并从中抽取根路径。这对于需要动态加载资源或进行页面间跳转的Web应用非常有用。
1234

被折叠的 条评论
为什么被折叠?



