Javascript: How to detect SVG in HTML img support?

javascript: How to detect SVG in HTML-img support?

I tried this, but it does not work:

x = new Image(); x.onload = function(){ if (x.width) { alert('svg in img tag supported!'); } }; x.src = 'test.svg'; 
+6
javascript svg detect
source share
2 answers

A good discussion / comparison of methods is here: http://www.voormedia.nl/blog/2012/10/displaying-and-detecting-support-for-svg-images

Based on this page, I ended up using this:

 svgsupport = document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image", "1.1") 
+2
source share

Use modernizr to detect such a function.

 if (Modernizr.SVG){ //svg supported } 
-one
source share

All Articles