【问题标题】:javascript: How to detect SVG in HTML img element support?javascript:如何在 HTML img 元素支持中检测 SVG?
【发布时间】:2011-02-15 10:15:43
【问题描述】:

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

我试过了,但它不起作用:

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

【问题讨论】:

标签: javascript svg detect


【解决方案1】:

这里有一个很好的讨论/比较方法: http://www.voormedia.nl/blog/2012/10/displaying-and-detecting-support-for-svg-images

基于该页面,我最终使用了这个:

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

【讨论】:

  • @Yaffle 这对你有用吗?接受轻推答案?
【解决方案2】:

像这样使用modernizr 进行特征检测。

if (Modernizr.SVG){
    //svg supported
}

【讨论】:

  • 这不会检查 img 元素中的支持。
猜你喜欢
  • 2011-05-06
  • 1970-01-01
  • 2011-10-26
  • 2012-10-07
  • 1970-01-01
  • 1970-01-01
  • 2012-05-01
  • 1970-01-01
  • 2010-10-13
相关资源
最近更新 更多