Skip to content

Instantly share code, notes, and snippets.

@clehner
Created March 26, 2010 22:35
Show Gist options
  • Save clehner/345486 to your computer and use it in GitHub Desktop.
Save clehner/345486 to your computer and use it in GitHub Desktop.
Simulate onhashchange support
// Simulate onhashchange support in all browsers
"onhashchange" in window || (function () {
var lastHash = '';
function pollHash() {
if (lastHash !== location.hash) {
lastHash = location.hash;
var event = document.createEvent("HTMLEvents");
event.initEvent("hashchange", true, false);
document.body.dispatchEvent(event);
if (typeof onhashchange == "function") {
onhashchange(event);
}
}
}
setInterval(pollHash, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment