Mike Mike - 1 year ago 129
Javascript Question

How to get the hashtag value and ampersand value of a url in Javascript?

I have a url like


Now I need to get the portion of url from starting from #, How do I get that, I tried using
but looks like that searches for ? in a url. is there a method to get the value of url after #

How do I also get a portion of url from ampersand &


Answer Source
var hash = window.location.hash;

More info here: https://developer.mozilla.org/en/DOM/window.location

Update: This will grab all characters after the hashtag, including any query strings. From the MOZ manual:

window.location.hash === the part of the URL that follows the # symbol, including the # symbol.
You can listen for the hashchange event to get notified of changes to the hash in
supporting browsers.

Now, if you need to PARSE the query string, which I believe you do, check this out here: Get query string values in JavaScript

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download