如何使用javascript获取应用程序路径 [英] How-to get the Application path using javascript
本文介绍了如何使用javascript获取应用程序路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我将我的应用程序托管在目录中。应用程序路径是目录名称。
If I have my application hosted in a directory. The application path is the directory name.
例如
http:// 192.168.1.2/AppName/some.html
如何在我的情况下使用javascript应用程序名称 / AppName
。
How to get using javascript the application name like in my case /AppName
.
document.domain
返回主机名和 document.URL
返回整个网址。
document.domain
is returning the hostname and document.URL
is returning the whole Url.
编辑
应用程序路径可能更复杂,例如 / one / two / thre /
Thr app path could be more complex, like /one/two/thre/
推荐答案
这会给你一个结果,但是如果你有更多级别就必须修改(见注释代码)。
This will give you a result but would have to be modified if you have more levels (see commented code).
var path = location.pathname.split('/');
if (path[path.length-1].indexOf('.html')>-1) {
path.length = path.length - 1;
}
var app = path[path.length-2]; // if you just want 'three'
// var app = path.join('/'); // if you want the whole thing like '/one/two/three'
console.log(app);
这篇关于如何使用javascript获取应用程序路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文