Created
September 21, 2021 15:28
-
-
Save dustinleer/2869a88da1509c6f01c4d87437fc598c to your computer and use it in GitHub Desktop.
Adds body class based on browser detection
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
function GetIEVersion() { | |
var sAgent = window.navigator.userAgent; | |
var Idx = sAgent.indexOf("MSIE"); | |
// If IE, return version number. | |
if (Idx > 0) { | |
return parseInt(sAgent.substring(Idx+ 5, sAgent.indexOf(".", Idx))); | |
// If IE 11 then look for Updated user agent string. | |
} else if (!!navigator.userAgent.match(/Trident\/7\./)) { | |
return 11; | |
} else { | |
return 0; //It is not IE | |
} | |
} | |
var ua = navigator.userAgent.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i), | |
browser; | |
if ( navigator.userAgent.match(/Edge/i) ) { | |
browser = 'edge'; | |
} else if ( navigator.userAgent.match(/Trident.*rv[ :]*11\./i) ) { | |
browser = 'ie'; | |
} else { | |
browser = ua[1].toLowerCase(); | |
} | |
if (GetIEVersion() > 0) { | |
$('body').addClass(browser); | |
} else { | |
$('body').addClass(browser); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment