Skip to content

Instantly share code, notes, and snippets.

@drejohnson
Last active August 29, 2015 14:04
Show Gist options
  • Save drejohnson/d08831f0b1a224bef562 to your computer and use it in GitHub Desktop.
Save drejohnson/d08831f0b1a224bef562 to your computer and use it in GitHub Desktop.
Small javascript snippet for adding mobile CSS classes
/* ios only styling */
.ios body {
background-color: #fff;
}
/* android only styling */
.android body {
background-color: #e7e7e7;
}
// https://coderwall.com/p/udfbcw
// By Sebastian Wallin
(function(d, l) {
for (var k in l) {
if(navigator.userAgent.match(new RegExp(l[k], 'i'))){
d[k] = true;
d.documentElement.className+=' '+k;
}
}
}(document, {
ios: '(iPhone|iPod|iPad)',
android: 'android',
mobile: 'mobile',
webview: '(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)'
}));
if (document.ios) {
// Do ios specific stuff
}
else if (document.android) {
// Do Android specific stuff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment