如何检测浏览器是否支持自定义元素 [英] how to detect if browsers support custom elements
问题描述
我正在寻找modernizr,它应该有助于功能检测,这大概是蜜蜂弄清楚了您的网站是否与给定的Web浏览器兼容,但是我看不到任何表明可以使用它的功能检测我们创建和创建的自定义HTML元素在我们的内容中定义.
I'm looking at modernizr which is supposed to help with feature detection which is supposedly the bees knees in figuring out if your website is compatible with a given web browser but I do not see anything that indicates that I can use it to detect custom HTML elements that we create & define in our content.
如果不是modernizr,如何可靠地检测浏览器是否能够以"HTML 5"方式处理自定义HTML元素?
If it's not modernizr, how do I reliably detect whether a browser is capable of handling custom HTML elements the "HTML 5" way?
推荐答案
Modernizr目前尚未对此进行测试,但是由于它具有用于创建元素的API,因此它应该与
Modernizr doesn't have a test for this at the moment, however since it has an API to create the element, it should be as simple as
var supportsCustomElements = ('registerElement' in document)
检测API的v0.要检查最新的v1,它的
to detect for v0 of the API. To check for the more up to date v1, its
var supportsCustomElements = ('customElements' in window)
(more info on the in
operator)
这篇关于如何检测浏览器是否支持自定义元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!