Puoi usare l'evento hashchange:
codice:
window.addEventListener("hashchange", function () {
    alert(location.hash);
});

// Io preferisco il primo modo, ma credo che si possa fare anche così:
window.onhashchange = funciton () {
    alert(location.hash);
};
Purtropoo quest'evento non è supportato da tutti i browser:
http://caniuse.com/hashchange

Esempio:
http://jsfiddle.net/Nicolo99/z3E6L/e...t,html,js,css/