Detecting support for a given JavaScript event?

Posted by Will on Stack Overflow See other posts from Stack Overflow or by Will
Published on 2010-05-20T20:04:15Z Indexed on 2010/05/20 20:10 UTC
Read the original article Hit count: 203

I'm interested in using the JavaScript hashchange event to monitor changes in the URL's fragment identifier. I'm aware of Really Simple History and the jQuery plugins for this. However, I've reached the conclusion that in my particular project it's not really worth the added overhead of another JS file.

What I would like to do instead is take the "progressive enhancement" route. That is, I want to test whether the hashchange event is supported by the visitor's browser, and write my code to use it if it's available, as an enhancement rather than a core feature. IE 8, Firefox 3.6, and Chrome 4.1.249 support it, and that accounts for about 20% of my site's traffic.

So, uh ... is there some way to test whether a browser supports a particular event?

Thanks.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about javascript-events