run function on hash change js code example
Example 1: js detect hash change
// Event listener
window.addEventListener("hashchange", e=>console.log('changed'), {});
// Event handler
window.onhashchange = e => console.log('changed');
// HTML event handler
<body onhashchange="funcRef();">
Example 2: javascript detect URL hash change
window.addEventListener("onhashchange", function(){
//url hash # has changed
});