-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
Nice! thanks!