1 2 3 4 |
var is_ie/*@cc_on = { // quirksmode : (document.compatMode=="BackCompat"), version : parseFloat(navigator.appVersion.match(/MSIE (.+?);/)[1]) }@*/; |
(Uncomment the second line if you also wish to check whether IE is running in “compatibility” (quirks) mode or in standards-mode.)
All other browsers cheerfully ignore the Javascript comment block (/* … */) so what they end up with is essentially this:
var is_ie;
…which evaluates as an implicit false, when used as a condition. This allows us to set up conditions like this one:
1 2 3 4 5 6 7 8 9 10 11 12 |
if (is_ie && (is_ie.version < 7)) { // do IE specific stuff } else if (is_ie && (is_ie.version >= 7)) { //do IE 7 or above specific stuff } else { // default behavior for other browsers } |
[reference : http://mar.anomy.net/entry/2006/11/23/00.06.40/ ]