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

前端 未结 8 1371
春和景丽
春和景丽 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:51

    The SVG-check did not work in Chrome because it specifies version 1.0. This should work better:

    document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Shape", "1.1")
    
    0 讨论(0)
  • 2020-11-29 18:56

    I'd suggest one tweak to crescentfresh's answer - use

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

    rather than

    document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Shape", "1.0")
    

    to detect SVG. WebKit is currently very picky about reporting features, and returns false for feature#Shape despite having relatively solid SVG support. The feature#BasicStructure alternative is suggested in the comments to https://bugs.webkit.org/show_bug.cgi?id=17400 and gives me the answers I expected on Firefox/Opera/Safari/Chrome (true) and IE (false).

    Note that the implementation.hasFeature approach will ignore support via plugins, so if you want to check for e.g. the Adobe SVG Viewer plugin for IE you'll need to do that separately. I'd imagine the same is true for the RENESIS plugin, but haven't checked.

    0 讨论(0)
提交回复
热议问题