Last active
August 29, 2015 14:03
-
-
Save dieppon/bbe20388b0260fbf682f to your computer and use it in GitHub Desktop.
Add classes to the HTML element based on os, browser's engine and browser client.
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
| jQuery(document).ready(function($) { | |
| // Add browser class to html | |
| if (navigator.userAgent.indexOf('Mac OS X') != -1) { | |
| // Mac | |
| if ($.browser.opera) { $('html').addClass('opera'); } | |
| if ($.browser.webkit) { $('html').addClass('webkit'); } | |
| if ($.browser.mozilla) { $('html').addClass('mozilla'); } | |
| if (/camino/.test(navigator.userAgent.toLowerCase())){ $('html').addClass('camino'); } | |
| if (/chrome/.test(navigator.userAgent.toLowerCase())) { $('html').addClass('chrome'); } | |
| if (navigator && navigator.platform && navigator.platform.match(/^(iPad|iPod|iPhone|iPhone Simulator|iPad Simulator)$/)) { | |
| $('html').addClass('ios'); | |
| if (navigator.platform.match(/^(iPad|iPad Simulator)$/)) { $('html').addClass('ipad'); } | |
| if (navigator.platform.match(/^(iPhone|iPhone Simulator)$/)) { $('html').addClass('iphone'); } | |
| if (navigator.platform.match(/^(iPod)$/)) { $('html').addClass('ipod'); } | |
| } | |
| if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) { $('html').addClass('safari'); } | |
| } else { | |
| // Not Mac | |
| if ($.browser.opera) { $('html').addClass('opera-pc'); } | |
| if ($.browser.webkit) { $('html').addClass('webkit-pc'); } | |
| if ($.browser.mozilla) { $('html').addClass('mozilla-pc'); } | |
| if (document.all && document.addEventListener) { $('html').addClass('ie9'); } | |
| if (/chrome/.test(navigator.userAgent.toLowerCase())) { $('html').addClass('chrome-pc'); } | |
| if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) { $('html').addClass('safari-pc'); } | |
| if ( navigator.userAgent.indexOf('Android') > -1 ) { $('html').addClass('android'); } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment