Skip to content
Advertisement

How do I get the fragment identifier (value after hash #) from a URL?

Example:

www.site.com/index.php#hello

Using jQuery, I want to put the value hello in a variable:

var type = …

Advertisement

Answer

No need for jQuery

var type = window.location.hash.substr(1);

Since String.prototype.substr is deprecated use substring instead.

var type = window.location.hash.substring(1);
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement