Skip to content

Instantly share code, notes, and snippets.

@cwardzala
Created July 11, 2013 15:29
Show Gist options
  • Save cwardzala/5976476 to your computer and use it in GitHub Desktop.
Save cwardzala/5976476 to your computer and use it in GitHub Desktop.
var platforms = [
{ category: 'windows', tokens: /(Windows)/i },
{ category: 'mac', tokens: /(Macintosh)/i },
{ category: 'iOS', tokens: /(iPad|iPhone|iPod)/i },
{ category: 'android', tokens: /(Android)/i },
{ category: 'silk', tokens: /(Silk)/i },
{ category: 'winmobile', tokens: /(Windows Phone OS|Zune)/i },
// Linux is tricky because Anroid reports itself as Linux.
// If you are using is.linux to detect desktop linux make sure you also check !is.android
{ category: 'linux', tokens: /(Linux)/i }
];
for (var i=0;i<platforms.length;i++) {
if (platforms[i].tokens.test(window.navigator.userAgent)) {
$('html').addClass('is-' + platforms[i].category);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment