Get the full url including hash with content in JavaScript

How can I get url with content after hash ?

window.location return me url without hash :/

for example:

window.location return only

Try window.location.hash this will work

this returns just content after hash



this will give us : prodid=1

If you only want the hash part you can use : window.location.hash

If you want all the url including the hash part, you can use : window.location.href


You have to build it up yourself:

var sansProtocol = window.location.hostname 
    + window.location.hash;

var full = window.location.protocol 
    + "//" 
    + window.location.hostname 
    + window.location.hash;

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   What does curly brackets in the `var { ... } = ...` statements do?

Similar Posts