How to detect the #hash and get the hash in JavaScript?

How to detect the #hash and get the hash in JavaScript? It's better if no additional library is needed. That said, jquery is fine if it is needed.

asked Oct 15, 2015 by anonymous

1 Answer

You can use this piece of JavaScript code:

if (window.location.hash) {
    // hash found
    var hash = window.location.hash.substring(1);
} else {
    // No hash
}
answered Oct 15, 2015 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...