2013-08-07 55 views

回答

1
var a = location.pathname + location.search 

如果由于某种原因,你也想的哈希也(URL的#部分),而不是使用:

var a = location.pathname + location.search + location.hash 

然后,你必须从a您的应用根路径:

a = a.replace("/MyApp/", ""); 
// or 
a = a.substring("/MyApp/".length); 
3

没有太多内置了这一点,因为你的应用与浏览器实际上不会同意什么““是。

到浏览器,/MyApp/仅仅是根,它说服下另一个目录名称是:

http://localhost:8080/ 

但是,如果你可以从你的应用程序获得了“基地”网址

var baseUrl = "http://localhost:8080/MyApp"; 

然后,您可以.replace(),从目前href

var pagePath = window.location.href.replace(baseUrl, ""); 

console.log(pagePath); 
// "/MyScreen?userName=ccc" 

实施例,使用一个模拟location对象:http://jsfiddle.net/CWcvW/