jQuery - hashchange event

Ian Herbert picture Ian Herbert · Jun 22, 2010 · Viewed 170.7k times · Source

I am using:

$(window).bind( 'hashchange', function(e) { });

to bind a function to the hash change event. This seems to work in IE8, Firefox and Chrome, but not in Safari and I assume not in earlier version of IE. For these browsers, I want to disable my JavaScript code that uses the hash and hashchange event.

Is there a way with jQuery that i can detect if the browser supports the hashchange event? Maybe something with jQuery.support...

Answer

Christian C. Salvadó picture Christian C. Salvadó · Jun 22, 2010

You can detect if the browser supports the event by:

if ("onhashchange" in window) {
  //...
}

See also: