没有文件的路径

时间:2012-02-15 16:30:02

标签: path document host

如何在没有文档名称的情况下获取文档路径?例如:

window.document.location 

给了我:http://host.com/lorem/ipsum/document.php
我只需要获得:http://host.com/lorem/ipsum/

非常乐意提供帮助。

2 个答案:

答案 0 :(得分:1)

var path = window.document.location;
path = path.substr(0, path.lastIndexOf('/'));

答案 1 :(得分:1)

var loc = location.href;
loc = loc.substring(0, loc.lastIndexOf("/"));