Skip to content

Instantly share code, notes, and snippets.

@ctcherry
Forked from KruegerDesigns/ios.html.class.js
Created February 1, 2012 18:28
Show Gist options
  • Save ctcherry/1718490 to your computer and use it in GitHub Desktop.
Save ctcherry/1718490 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');
}
});
@KruegerDesigns
Copy link

Very nice, thanks Chris! I may need to use this down the road.

@Lastmanu
Copy link

Nice! thanks!

@sh4msi
Copy link

sh4msi commented Jun 4, 2017

Very Nice 👍
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment