Skip to content

Instantly share code, notes, and snippets.

@Ivanca
Created December 17, 2012 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ivanca/4314663 to your computer and use it in GitHub Desktop.
Save Ivanca/4314663 to your computer and use it in GitHub Desktop.
Get Internet Explorer version; or return undefined if it is NOT internet explorer. Modded from james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/ Unfortunately IE10 doesn't accept HTML conditional statements, so we have to use a JS conditional statement.
var ie = (function(){
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
do {
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->';
} while(all[0]);
/*@cc_on;if(v<5)v=10;@*/
return v > 4 ? v : undef ;
}());
@Ivanca
Copy link
Author

Ivanca commented Dec 17, 2012

E.g.

    if(ie < 9){
        // Do something if is IE 8 or IE 7 or IE 6
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment