For those interested in the reusable version of the Andy E. solution, I made a simple function to get the actual hash state as a bit value.
function getHashState(href) {
var frag = (href || window.location.href).split('#');
return frag.length == 1 ? 1 : !frag[1].length ? 2 : 4;
}
You can easily compare returned values ββwith the bitwise AND operator ( &).
if (getHashState() & 1); // no hash
if (getHashState() & 2); // empty hash
if (getHashState() & 4); // no empty hash
source
share