JavaScript detectar el cambio de hash de URL

window.addEventListener("onhashchange", function(){
    //url hash # has changed
});
Grepper