Last active
December 17, 2015 20:19
-
-
Save ahawthorne/5666557 to your computer and use it in GitHub Desktop.
JavaScript to detect IE version using conditional tags and add classes to the html tag.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.ie = (function() { | |
var undef, | |
v = 3, | |
htmlClass = document.documentElement.className, | |
div = document.createElement('div'), | |
all = div.getElementsByTagName('span'); | |
do { | |
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><span></span><!endif]-->'; | |
} while (all[0]); | |
return v > 4 ? v : undef; | |
})(); | |
(function() { | |
var ieClass = ''; | |
// add classes to html | |
switch (window.ie) { | |
case 9: | |
ieClass = 'ie9'; | |
break; | |
case 8: | |
ieClass = 'lt-ie9 ie8'; | |
break; | |
case 7: | |
ieClass = 'lt-ie9 lt-ie8 ie7'; | |
break; | |
} | |
document.documentElement.className = ieClass; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment