获取包含带有JavaScript内容的哈希的完整url

如何在哈希后获取内容的url?

window.location返回没有哈希的url:/

例如:

www.mystore.com#PRODID = 1

window.location仅返回www.mystore.com

window.location.hash 

https://developer.mozilla.org/en/window.location

请注意属性部分。

试试window.location.hash这会有效

这会在哈希后返回内容

 window.location.hash.substr(1); 

例如: www.mystore.com#prodid=1

这将给我们: prodid=1

如果您只想要哈希部分,可以使用: window.location.hash

如果您想要包含散列部分的所有url,可以使用: window.location.href

问候

你必须自己建立它:

 // www.mystore.com#prodid=1 var sansProtocol = window.location.hostname + window.location.hash; // http://www.mystore.com#prodid=1 var full = window.location.protocol + "//" + window.location.hostname + window.location.hash;