javascripthtmlmodernizr

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?


Solution

  • 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)