Skip to content

Instantly share code, notes, and snippets.

@sh4msi
Forked from ctcherry/iOSclass
Created June 4, 2017 15:55
Show Gist options
  • Save sh4msi/aeb2b1fb546d8eb67d3afd1761bd2e9a to your computer and use it in GitHub Desktop.
Save sh4msi/aeb2b1fb546d8eb67d3afd1761bd2e9a to your computer and use it in GitHub Desktop.
Add mobile class to html tag for mobile devices along with the mobile type if known
// adds mobile class, and mobile os to html tag
jQuery(document).ready(function($){
var deviceAgent = navigator.userAgent.toLowerCase();
if (deviceAgent.match(/(iphone|ipod|ipad)/)) {
$('html').addClass('ios');
$('html').addClass('mobile');
}
if (deviceAgent.match(/android/)) {
$('html').addClass('android');
$('html').addClass('mobile');
}
if (deviceAgent.match(/blackberry/)) {
$('html').addClass('blackberry');
$('html').addClass('mobile');
}
if (deviceAgent.match(/(symbianos|^sonyericsson|^nokia|^samsung|^lg)/)) {
$('html').addClass('mobile');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment