how to detect if browsers support custom elements

本秂侑毒 提交于 2019-12-06 05:06:22

问题


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.

If it's not modernizr, how do I reliably detect whether a browser is capable of handling custom HTML elements the "HTML 5" way?


回答1:


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)

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)



来源:https://stackoverflow.com/questions/25096743/how-to-detect-if-browsers-support-custom-elements

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