Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect if browsers support custom elements

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?

like image 641
this Avatar asked Aug 02 '14 15:08

this


People also ask

How do you determine if the browser supports a certain feature?

The concept of feature detection The idea behind feature detection is that you can run a test to determine whether a feature is supported in the current browser, and then conditionally run code to provide an acceptable experience both in browsers that do support the feature, and browsers that don't.

Does Safari support custom elements?

New! Save questions or answers and organize your favorite content. Learn more.

Can you use custom elements in HTML?

One of the key features of the Web Components standard is the ability to create custom elements that encapsulate your functionality on an HTML page, rather than having to make do with a long, nested batch of elements that together provide a custom page feature.


1 Answers

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)

like image 129
Patrick Avatar answered Oct 20 '22 20:10

Patrick