Last active
January 2, 2016 15:49
-
-
Save astromac/8325565 to your computer and use it in GitHub Desktop.
Adds class to the html tag in order to address any styling quirks specific to those brosers. Example class might be "IE IE-9" or "iOS iO7-iPad".
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
// Detect IE and iOS and add browser class to document | |
var tag = document.getElementsByTagName('html')[0]; | |
var ua = navigator.userAgent; | |
var version = ''; | |
if (/msie (\d+)/i.test(ua)) { | |
version = 'IE IE-' + /msie (\d+)/i.exec(ua)[1]; | |
if (tag.className.length > 0) { | |
tag.className = tag.className + ' ' + version; | |
} else { | |
tag.className = version; | |
} | |
} else if (/trident.*?; rv:(\d+)/i.test(ua)) { | |
version = 'IE IE-' + /trident.*?; rv:(\d+)/i.exec(ua)[1]; | |
if (tag.className.length > 0) { | |
tag.className = tag.className + ' ' + version; | |
} else { | |
tag.className = version; | |
} | |
} else if (/\((\w+).*?OS (\d).*?like Mac OS X/i.test(ua)) { | |
version = 'iOS iOS' + /\((\w+).*?OS (\d).*?like Mac OS X/i.exec(ua)[2] + '-' + /\((\w+).*?OS (\d).*?like Mac OS X/i.exec(ua)[1]; | |
if (tag.className.length > 0) { | |
tag.className = tag.className + ' ' + version; | |
} else { | |
tag.className = version; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment