Modernizr can detect CSS 3D transforms, yeah. The truthiness of Modernizr.csstransforms3d
will tell you if the browser supports them.
The above link lets you select which tests to include in a Modernizr build, and the option you're looking for is available there.
Alternatively, as user356990 answered, you can use conditional comments if you're searching for IE and IE alone. Rather than creating a global variable, you can use HTML5 Boilerplate's <html>
conditional comments trick to assign a class:
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
If you already have jQuery initialised, you can just check with $('html').hasClass('lt-ie9')
. If you need to check which IE version you're in so you can conditionally load either jQuery 1.x or 2.x, you can do something like this:
myChecks.ltIE9 = (function(){
var htmlElemClasses = document.querySelector('html').className.split(' ');
if (!htmlElemClasses){return false;}
for (var i = 0; i < htmlElemClasses.length; i += 1 ){
var klass = htmlElemClasses[i];
if (klass === 'lt-ie9'){
return true;
}
}
return false;
}());
N.B. IE conditional comments are only supported up to IE9 inclusive. From IE10 onwards, Microsoft encourages using feature detection rather than browser detection.
Whichever method you choose, you'd then test with
if ( myChecks.ltIE9 || Modernizr.csstransforms3d ){
// iframe or flash fallback
}
Don't take that ||
literally, of course.