admin 管理员组

文章数量: 1086019

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 patible 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?

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 patible 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?

Share Improve this question asked Aug 2, 2014 at 15:46 thisthis 1,42612 silver badges23 bronze badges 3
  • You really don't have to. If you include the code that makes old versions of IE work properly, then your non-standard elements will work on all modern browsers. It's a questionable practice, however, to do that anyway. – Pointy Commented Aug 2, 2014 at 15:48
  • 1 Let me clarify - the intention is to not support old versions and notify users that they need to upgrade the browsers. We have no intention of supporting older browsers. – this Commented Aug 2, 2014 at 16:40
  • Ah. Well I'm not sure how you'd check for that; there are probably different things that happen in different old browsers when an unknown tag is encountered. – Pointy Commented Aug 2, 2014 at 16:55
Add a ment  | 

2 Answers 2

Reset to default 9

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)

Old thread, but just wanted to say that Modernizer is supporting it now.

本文标签: javascripthow to detect if browsers support custom elementsStack Overflow