2013-08-07 54 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/