Sniffing IE9 features while in compatibility mode

Getting the browser version from the User Agent string is one thing. But, when you force compatibility mode in IE, you get whatever version you’re forcing to. e.g…

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>

in IE9 will cause jQuery’s

($.browser.version, 10)

to return “8” :(

I started digging through some msdn docs to find various ways of sniffing the actual browser we’re using, even when compatibility mode is forced. This led me to this doc Which talks about how IE9’s Chakra JavaScript engine processes math precision differently (and faster) than the old IE8 JScript engine.

So using the following bit of code, we are able to detect the true browser version no matter what compatibility mode it’s in.

if ($.browser.msie && parseInt($.browser.version, 10) <= 8) {
var x = 6.28318530717958620000;
var val = Math.sin(x);
  if(Math.abs(val) === 2.4492127076447545e-16){
  //do your IE6,7,8 shit here

Easier/better way?

Words by Wesley Hales