javascript: How to detect SVG in HTML img element support?
javascript: How to detect SVG in HTML img element support?
I tried this, but it doesn't work:
x = new Image();
x.onload = function(){
if (x.width) {
alert('svg in img开发者_JAVA百科 tag supported!');
}
};
x.src = 'test.svg';
A good discussion/comparison of methods is here: http://www.voormedia.nl/blog/2012/10/displaying-and-detecting-support-for-svg-images
Based on that page, I wound up using this:
svgsupport = document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image", "1.1")
Use modernizr for feature detection like this.
if (Modernizr.SVG){
//svg supported
}
精彩评论