Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to perform all Modernizr tests all at once?

I'm new to Modernizr and I'm just looking for a simple way to check for overall browser compatibility. I've generated a Modernizr script to test for only the most essential components of my web application, which is highly dependent on HTML5, CSS3, and modern JavaScript methods. Is there a way to run all of these tests simultaneously? Looking over the documentation, I see plenty of ways to test each feature one by one, but I'm not seeing a way to do it all at once. I'm hoping to do something like this:

Pseudocode

if (Modernizr.testAll()) {
  // Load site
} else {
  // Redirect to compatibility page
}
like image 305
David Jones Avatar asked Aug 31 '13 23:08

David Jones


1 Answers

It turns out that all the tests are stored as booleans directly in the Modernizr object, so if you're building an application with a lot of feature dependencies and you want to test them all at once, use this:

var supported = true;
for (var feature in Modernizr) {
  if (typeof Modernizr[feature] === "boolean" && Modernizr[feature] == false) {
    supported = false;
    break;
  }
}
like image 144
David Jones Avatar answered Nov 15 '22 11:11

David Jones