Puoi usare l'evento hashchange:
Purtropoo quest'evento non è supportato da tutti i browser: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); };
http://caniuse.com/hashchange
Esempio:
http://jsfiddle.net/Nicolo99/z3E6L/e...t,html,js,css/