特征检测:JavaScript中的突变事件可用性? [英] Feature-detect: mutation-event availability in JavaScript?
问题描述
我的JavaScript如何检测事件是否可用?
我知道一些很棒的事件兼容性表< a>,但我需要使用功能检测,而不是浏览器嗅探加一个查找表。
具体来说,我的JS极大地利用了DOM变异事件c $ c> DOMNodeInserted 和 DOMSubtreeModified
) - 除非(当然)Internet Explorer。
$ b
那么,如何检测浏览器是否支持 DOMNodeInserted
?
如果你只是想检查浏览器是否支持一般的突变事件,你可以使用这个简单的测试:
code> var hasMutationEvents =(MutationEventin window);
以下是一些流行浏览器的结果:
http://www.browserscope.org/browse?category=usertest_agt1YS1wcm9maWxlcnINCxIEVGVzdBjEkNAPDA
要在另一个浏览器中运行browserscope测试,请访问:
http://jsbin.com/aqeton/4/
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/
这篇关于特征检测:JavaScript中的突变事件可用性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!