2

What's the simplest, most reliable way to test if a browser / user agent / client supports the Raphael.js library? Raphael uses Javascript to create and control SVG vector graphics, or, if SVG isn't available but VML is (e.g. in Internet Explorer versions 6 to 8), it creates and controls equivalent graphics using VML.

One method would be to feature-detect SVG, then, if it's not available, feature-detect VML. There's an old question from 2009 with answers including some code for feature-detecting VML and SVG. However, the comments suggest that it might not work in all cases, and I'm sure a lot has changed since 2009. Also, there might be a simpler way specific to Raphael.

A simpler alternative might be to use some Raphael internal flags or functions. It already sets variables for whether it is operating in SVG mode or VML mode. Can this be used to reliably detect a 'neither' condition?

Or maybe there's a reliable approach based on creating an empty Raphael object and testing its properties or functions?


For general background, as far as I know the only common browser to not be compatible with Raphael is the Android stock browser in versions 1.x and 2.x, however, I'd prefer to use feature detection rather than browser version detection if possible (unless there's a good reason why that's actually unusually a better solution in this case).

Community
  • 1
  • 1
user56reinstatemonica8
  • 32,576
  • 21
  • 101
  • 125

1 Answers1

6

Check the official docs: http://raphaeljs.com/reference.html#Raphael.type

if (!Raphael.type) alert('Your browser does not support vector graphics!');
Rango
  • 3,877
  • 2
  • 22
  • 32
  • 1
    As today, this is the correct link http://dmitrybaranovskiy.github.io/raphael/reference.html#Raphael.type – Chux Jul 12 '16 at 16:12