24
$\begingroup$

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

$\endgroup$
1

5 Answers 5

33
$\begingroup$
window.location.hash

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

Note the properties section.

$\endgroup$
Sign up to request clarification or add additional context in comments.

Comments

10
$\begingroup$

Try window.location.hash this will work

$\endgroup$

Comments

3
$\begingroup$

this returns just content after hash

window.location.hash.substr(1);

ex: www.mystore.com#prodid=1

this will give us : prodid=1

$\endgroup$

2 Comments

The question is not asking for just the hash content.
This extracts what's after the hash buddy. Begin the extraction at position 1, and extract the rest of the string ;). but when we use substr(x, y) we extract from x to y.
2
$\begingroup$

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

$\endgroup$

Comments

1
$\begingroup$

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;
$\endgroup$

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.