Created
December 6, 2011 19:50
-
-
Save dbergey/1439654 to your computer and use it in GitHub Desktop.
Browser-Specific Classes
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
// add OS-specific classes for targeting a whole set of browser on one OS. | |
$('html').addClass('browser-os-'+ ( | |
navigator.userAgent.match(/Macintosh/) ? 'macos' : | |
navigator.userAgent.match(/Windows/) ? 'windows' : | |
navigator.userAgent.match(/Linux/) ? 'linux' : | |
'unknown') | |
) | |
// now add more general browser classes for targeting all version of any one browser. IE disabled since conditional comments added. | |
.addClass('browser-'+ ( | |
$.browser.msie ? 'ie' : | |
$.browser.mozilla ? 'ff' : | |
$.browser.webkit ? 'wk' : | |
$.browser.opera ? 'op' : | |
'unknown') | |
) | |
// make the classes more concise than the tokens jQuery returns, also add version | |
.addClass('browser-'+ ( | |
$.browser.msie ? 'ie-' + navigator.userAgent.match(/MSIE ([\d]+)/ )[1] : | |
$.browser.mozilla ? 'ff-' + navigator.userAgent.match(/Firefox\/(\d\.\d?)/)[1] : | |
$.browser.webkit ? 'wk-' + navigator.userAgent.match(/WebKit\/(\d+)/)[1] : | |
$.browser.opera ? 'op-' + navigator.userAgent.match(/Version\/([\d.]+)/)[1] : | |
'unknown').replace('.', '-') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use Modernizr when you can. This is for purely visual inconsistencies.