JS 获取网站根目录 域名+站名
//获取根路径
function getBasePath() {
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);
}
注:需要在VS或者 IIS中测试
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 网站根目录与服务器根目录 设置
- 下一篇: Tomcat中更改网站根目录和默认页的配置方法
