24

How can I get url with content after hash ?

window.location return me url without hash :/

for example:

www.mystore.com#prodid=1

window.location return only www.mystore.com

Jannie Theunissen
  • 28,256
  • 21
  • 100
  • 127
gruber
  • 28,739
  • 35
  • 124
  • 216
  • 1
    Take a look at this: http://stackoverflow.com/questions/298503/how-can-you-check-for-a-hash-in-a-url-using-javascript – Petteri H Jul 21 '11 at 15:57

5 Answers5

33
window.location.hash

https://developer.mozilla.org/docs/Web/API/Window/location

Note the properties section.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Brad Christie
  • 100,477
  • 16
  • 156
  • 200
10

Try window.location.hash this will work

ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
3

this returns just content after hash

window.location.hash.substr(1);

ex: www.mystore.com#prodid=1

this will give us : prodid=1

Tarik FAMIL
  • 439
  • 5
  • 9
2

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

Regards

1000i100
  • 400
  • 1
  • 3
  • 13
1

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;
Jannie Theunissen
  • 28,256
  • 21
  • 100
  • 127