How can I trigger on URL change in jQuery?
var current_href = location.href;
setInterval(function(){
if(current_href !== location.href){
// if changed Do ...
current_href = location.href;
}else{
// Do ...
}
},500);
This worked for me ^^
$(window).on('hashchange') // not firing
Try the hashchange
event, which is built exactly for this - http://benalman.com/projects/jquery-hashchange-plugin/
That would be a hashchange
event, so I'd suggest:
$(window).on('hashchange', function(e){
// do something...
});
JS Fiddle demo.
References:
on()
.