Feature-detect: mutation-event availability in JavaScript?

断了今生、忘了曾经 提交于 2019-12-05 03:33:16

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/

Robin Winslow

This question is quite old, but in case anyone else stumbles upon it, a solution for detecting mutation events is explained in this answer: How to check browser support for capabilities / events?

From that answer:

You can't detect mutation events, and modernizr doesn't work for this...

The only way to "detect" support for mutation events is to try and trigger the event.

For normal events, use the perfectionkills article in takteek's answer. This still doesn't seem to support sniffing of some new HTML5 events, like "input".

I looked around on google a bit. This looks like it's probably what you want:

http://perfectionkills.com/detecting-event-support-without-browser-sniffing/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!