Reputation: 135
I am trying to detect browser using following code,
if ($.browser.msie && parseInt($.browser.version) >= 9)
but in IE9 compatibility mode with IE7 document standards it is giving browser version as IE 7. Is there any other way to do this?
Upvotes: 1
Views: 3261
Reputation: 927
I wrote a JavaScript function, ie-truth, to determine both the true IE version, and the compatibility mode IE is running as for this kind of case. By parsing the User Agent String and looking at both the Trident and MSIE numbers, you're able to determine both factors.
Upvotes: 0
Reputation: 5945
Here's an easy way to check for compatibility mode:
try{ JSON } catch (e){ alert("Compatibility Mode Detected") }
The JSON object is undefined when in compatibility mode.
Upvotes: 5
Reputation: 10127
You should not check for a specific browser version but rather if the current browser is capable of doing what you want (e.g. opacity, rounded corners etc.)
Consider using the Modernizr framework that added several classes to the html
tag you can use in your stylesheet to apply certain styles under certain conditions.
Upvotes: 0