How do you detect support for VML or SVG in a browser

前端 未结 8 1406
春和景丽
春和景丽 2020-11-29 18:12

I\'m writing a bit of javascript and need to choose between SVG or VML (or both, or something else, it\'s a weird world). Whilst I know that for now that only IE supports VM

8条回答
  •  被撕碎了的回忆
    2020-11-29 18:47

    The SVG check didn't work for me in Chrome, so I looked at what the Modernizer library does in their check (https://github.com/Modernizr/Modernizr/blob/master/modernizr.js).

    Based on their code, this is what worked for me:

    function supportsSVG() {
        return !!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect;
      }
    

提交回复
热议问题