最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to detect if browsers support custom elements - Stack Overflow

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论