当前位置: 首页 > 新闻动态 > 软件编程

获取网站跟路径的javascript代码(站点及虚拟目录)

作者:用户投稿 浏览: 发布日期:2026-01-16
[导读]:js获取网站根路径(站点及虚拟目录) ,需要的朋友可以参考下。
复制代码 代码如下:
<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>
免责声明:转载请注明出处:http://shjed.com/news/27317.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!