Skip to content

Instantly share code, notes, and snippets.

@wallin
Created January 3, 2014 12:59
Show Gist options
  • Save wallin/8237512 to your computer and use it in GitHub Desktop.
Save wallin/8237512 to your computer and use it in GitHub Desktop.
Simple way of detecting and adding body-classes for mobile devices. Classes added: 'mobile', 'iphone', 'android'
(function(d, l, c) {
while(c=l.pop()){
if(navigator.userAgent.match(new RegExp(c, 'i'))){
d[c]=!0;
d.documentElement.className+=' '+c;
}
}
}(document, ['iphone', 'mobile', 'android']));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment