javascript:如何在HTML img元素支持中检测SVG?

Yaf*_*fle 6 javascript svg detect

javascript:如何在HTML img元素支持中检测SVG?

我试过这个,但它不起作用:

x = new Image();
x.onload = function(){
  if (x.width) {
   alert('svg in img tag supported!');
  }
};
x.src = 'test.svg';
Run Code Online (Sandbox Code Playgroud)

Asc*_*iom -1

使用Modernizr进行这样的特征检测。

if (Modernizr.SVG){
    //svg supported
}
Run Code Online (Sandbox Code Playgroud)