Detect hashchange and hash existed code run duplicate?

https://stackoverflow.com/questions/33056521/detect-hashchange-and-hash-existed-code-run-duplicate

var hash = '';
$(document).load(function() {
$(window).trigger('hashchange');
});

$(window).on('hashchange', function() {
if (hash == window.location.hash) {
// do nothing, hash is the same as it was previously
return;
}

hash = window.location.hash;

if (hash) {
    alert("Apple");
}

});

Subscribe to Code, Query, Ship, and Learn

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe