哪种SVG支持检测方法最好? [英] Which SVG support detection method is best?
本文介绍了哪种SVG支持检测方法最好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人已经问过我关于在浏览器中检测SVG支持的问题但是有三个主要的解决方案,而不是关于每个优点的讨论。
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.
所以:哪个,如果有的话, 是最好的?在便携性和正确性方面,即。假阴性(即无svg)是不合需要的,但可以接受;误报不是。
So: which, if any, is best? In terms of portability and correctness, that is. False negatives (i.e. "no svg") are undesirable, but acceptable; false positives are not.
图表A:
var testImg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNzUiIGhlaWdodD0iMjc1Ij48L3N2Zz4%3D';
var img = document.createElement('img')
img.setAttribute('src',testImg);
return img.complete;
图表B:
return document.implementation.hasFeature(
"http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1");
图表C:
return !! document.createElementNS &&
!! document.createElementNS (
'http://www.w3.org/2000/svg',
"svg")
.createSVGRect;
推荐答案
我可能会使用 modernizr 。
这篇关于哪种SVG支持检测方法最好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文