Last active
August 29, 2015 14:07
-
-
Save RemeJuan/31ef5fffdc05ede8309e to your computer and use it in GitHub Desktop.
Detect browser version using HTTP headers, add a class to the body tag as well as set a variable.
This file contains 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
//Check browser version and apply classes to body where applicable | |
var body = document.getElementsByTagName('body')[0], | |
browserName, | |
browserVersion, | |
userAgent = navigator.appVersion.toLowerCase(); | |
if (userAgent.indexOf("msie 8.") !== -1) | |
{ | |
body.classList.add('ie8'); | |
browserName = 'ie'; | |
browserVersion = 'ie8'; | |
} | |
if (userAgent.indexOf("msie 9.") !== -1) | |
{ | |
body.classList.add('ie9'); | |
browserName = 'ie'; | |
browserVersion = 'ie9'; | |
} | |
if (userAgent.indexOf("msie 10.") !== -1) | |
{ | |
body.classList.add('ie10'); | |
browserName = 'ie'; | |
browserVersion = 'ie10'; | |
} | |
if (userAgent.indexOf("rv:11.") !== -1) | |
{ | |
body.classList.add('ie11'); | |
browserName = 'ie'; | |
browserVersion = 'ie11'; | |
} | |
if (userAgent.indexOf("edge/12") !== -1) | |
{ | |
body.classList.add('ie12'); | |
browserName = 'ie'; | |
browserVersion = 'ie12'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment