23

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
  • 25,269
  • 20
  • 97
  • 121
gruber
  • 26,743
  • 31
  • 120
  • 211
  • 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.

Chris
  • 112,704
  • 77
  • 249
  • 231
Brad Christie
  • 98,427
  • 16
  • 148
  • 198
10

Try window.location.hash this will work

ShankarSangoli
  • 68,720
  • 11
  • 89
  • 123
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
  • 380
  • 1
  • 3
  • 12
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
  • 25,269
  • 20
  • 97
  • 121