获取完整的 url,包括带有 JavaScript 内容的哈希
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6778990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get the full url including hash with content in JavaScript
提问by gruber
How can I get url with content after hash ?
如何在哈希后获取包含内容的 url?
window.location return me url without hash :/
window.location 返回没有哈希的 url :/
for example:
例如:
www.mystore.com#prodid=1
www.mystore.com#prodid=1
window.location return only www.mystore.com
window.location 只返回 www.mystore.com
回答by Brad Christie
window.location.hash
https://developer.mozilla.org/en/window.location
https://developer.mozilla.org/en/window.location
Note the propertiessection.
注意属性部分。
回答by ShankarSangoli
Try window.location.hash
this will work
试试window.location.hash
这个会起作用
回答by Tarik FAMIL
this returns just content after hash
这在哈希后只返回内容
window.location.hash.substr(1);
ex: www.mystore.com#prodid=1
前任: www.mystore.com#prodid=1
this will give us : prodid=1
这会给我们: prodid=1
回答by 1000i100
If you only want the hash part you can use : window.location.hash
如果你只想要哈希部分,你可以使用: window.location.hash
If you want all the url including the hash part, you can use : window.location.href
如果你想要包括哈希部分的所有 url,你可以使用: window.location.href
Regards
问候
回答by Jannie Theunissen
You have to build it up yourself:
你必须自己建立它:
// 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;