I have this jquery code:
$(window).on('hashchange popstate', function() {
someFunction();
});
I want to run someFunction() if the hash changes and also if the hash is removed. It seems like 'hashchange' does not fire if the hash is simply removed so therefore I have to use popstate as well. My problem now is that this is most often triggered twice, how can I avoid that?
I simply want the hashchange event plus the case when the hash is removed.
You could try to debounce it a little bit:
To avoid global var: