Skip to content Skip to sidebar Skip to footer

Which Svg Support Detection Method Is Best?

Somebody has already asked my question about detecting SVG support in browsers but there are three leading solutions and not a lot of discussion about the merits of each. So: which

Solution 1:

No need to include the entire Modernizr library for this. Here's a simple check that I've used in the past:

typeof SVGRect !== "undefined"; //trueif supported, falseifnot

This quite simply checks for support of the SVGRect object which is defined in the SVG Specification. In Chrome, typeof SVGRect is "function" and in IE9 it's "object", but in browsers which do not support SVG (IE8, for instance) this returns "undefined".

With the above code, you can simply:

if (typeof SVGRect !== "undefined") { ... /* If the browser does support SVG. */ }
else { ... /* If the browser does not support SVG. */ }

Solution 2:

Currently, Modernizr uses approach B to detect for support for SVGs in <img> tags, and approach C to detect for support for SVGs in <embed> and <object> tags. It seems it used to use an approach that was more like A for detecting for "SVG as img" support, but that was dropped in favour of B (for more detail, see this post on CSS-tricks).

Consequently, it seems that at the moment, either B or C would be the best approach, depending on what exactly you want to test for.

Solution 3:

I would probably use modernizr.

Post a Comment for "Which Svg Support Detection Method Is Best?"