2014-02-10 186 views

回答

30

您有:

window.location.href 

也:

document.URL 
5

如果你想返回整個URL,你需要使用window.location.href

使用window.location.pathname僅返回其排除查詢參數和片段的URL(即,起始於/以下的主機但僅達到一?#)的路徑部分。

實施例:

> window.location.pathname 
"/ebook" 
> window.location.href 
"http://example.com/ebook?page=43" 

此外,請參閱更多可用的屬性爲window.location的文檔。

相關問題