javascript - How to check browser support for capabilitiesevents? - Stack Overflow

In the past we used browser sniffing to infer if certain events or capabilities were available. I under

In the past we used browser sniffing to infer if certain events or capabilities were available. I understand that browser sniffing has been 'deprecated' or 'shunned' in favor of feature sniffing. I would like to know how I can check if a certain event can be handled.

Take DOMNodeInserted for example. It is supported by Chrome, FF and Safari, but not by IE. How can I sniff if this event is available? Is there a library present? How do you guys do proper feature sniffing?

In the past we used browser sniffing to infer if certain events or capabilities were available. I understand that browser sniffing has been 'deprecated' or 'shunned' in favor of feature sniffing. I would like to know how I can check if a certain event can be handled.

Take DOMNodeInserted for example. It is supported by Chrome, FF and Safari, but not by IE. How can I sniff if this event is available? Is there a library present? How do you guys do proper feature sniffing?

Share Improve this question edited Sep 24, 2013 at 4:27 000 27.3k10 gold badges74 silver badges103 bronze badges asked Apr 19, 2011 at 7:50 Kees C. BakkerKees C. Bakker 33.5k31 gold badges118 silver badges207 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

You can't detect mutation events, and modernizr doesn't work for this (since people are going to spit that out as the defacto answer).

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

var div = document.createElement('div'), supported = false;
div.addEventListener('DOMNodeInserted', function(){ supported = true; });
div.appendChild(div.cloneNode(true));

Note that the above code will not work as-is if it's in linear code because the event listener is async. The general idea is valid, however, perhaps best implemented with a callback.

Checkout http://www.modernizr.

To answer the generic - how do I do feature sniffing - I use the jQuery.support object.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745585223a4634495.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信