Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created January 12, 2012 10:27
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/1599740 to your computer and use it in GitHub Desktop.
Save Integralist/1599740 to your computer and use it in GitHub Desktop.
Detect `onhashchange` support
var docmode = document.documentMode;
// Does the browser support window.onhashchange?
// Note that IE8 running in IE7 compatibility mode reports true for 'onhashchange' in window,
// even though the event isn't supported, so also test document.documentMode.
if ('onhashchange' in window && (docmode === undefined || docmode > 7 )) {
window.onhashchange = checkHash;
}
// IE7 doesn't support the hashchange event so we fall back to standard polling technique
else {
poll = window.setInterval(checkHash, 500);
// Clean-up objects as IE7 has hideous performance
window.onunload = function() {
window.clearInterval(poll);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment