Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - hashchange event

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...

like image 879
Ian Herbert Avatar asked Jun 22 '10 05:06

Ian Herbert


People also ask

What is Hashchange event?

The hashchange event is fired when the fragment identifier of the URL has changed (the part of the URL beginning with and following the # symbol).

What is jQuery Hashchange?

The jQuery Mobile . hashchange() event handler enables very basic bookmarkable #hash history by providing a callback function bound to the window. onhashchange event. The onhashchange event fires when a window's hash changes. In browsers that support it, the native HTML5 window.


1 Answers

You can detect if the browser supports the event by:

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

See also:

  • Detecting event support without browser sniffing
  • Emulating onhashchange without setInterval
  • window.onhashchange
like image 138
Christian C. Salvadó Avatar answered Sep 30 '22 11:09

Christian C. Salvadó