gruber
gruber

Reputation: 29719

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:

www.mystore.com#prodid=1

window.location return only www.mystore.com

Upvotes: 24

Views: 21806

Answers (5)

Brad Christie
Brad Christie

Reputation: 101594

window.location.hash

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

Note the properties section.

Upvotes: 33

Jannie Theunissen
Jannie Theunissen

Reputation: 30144

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;

Upvotes: 1

Tarik FAMIL
Tarik FAMIL

Reputation: 449

this returns just content after hash

window.location.hash.substr(1);

ex: www.mystore.com#prodid=1

this will give us : prodid=1

Upvotes: 3

1000i100
1000i100

Reputation: 409

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

Upvotes: 2

ShankarSangoli
ShankarSangoli

Reputation: 69905

Try window.location.hash this will work

Upvotes: 10

Related Questions