How can my JavaScript detect if an event is available?
I'm aware of some great event-compatibility tables, but I need to use feature detection, not browser-sniffing plus a lookup table.
Specifically, my JS makes great use of the DOM mutation events (DOMNodeInserted
and DOMSubtreeModified
) -- which work great in all browsers except (of course) Internet Explorer.
So, how would I detect if a browser supports DOMNodeInserted
?
If you just want to check if the browser supports mutation events in general, you can use this simple test:
var hasMutationEvents = ("MutationEvent" in window);
Here are the results from a bunch of popular browsers: http://www.browserscope.org/browse?category=usertest_agt1YS1wcm9maWxlcnINCxIEVGVzdBjEkNAPDA
To run the browserscope test in another browser go here: http://jsbin.com/aqeton/4/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With