Created
May 16, 2012 03:53
-
-
Save girvan/2707228 to your computer and use it in GitHub Desktop.
detect mobile / tablet device and insert into body class
This file contains 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
// this project is move to https://github.com/girvan/mobile-detection | |
(function(){ | |
var device = '', _ipad = 'ipad', _iphone = 'iphone', ua = navigator.userAgent.toLowerCase(); | |
if( ua.indexOf(_ipad) != -1 ) | |
device = 'ios tablet ' + _ipad; | |
else if( ua.indexOf(_iphone) != -1 ) | |
device = 'ios mobile ' + _iphone; | |
else if( ua.match(/android/) ) | |
{ | |
device = 'android'; | |
if(ua.indexOf('mobile')==-1) | |
device += ' tablet'; | |
else | |
device += ' mobile'; | |
} | |
if(device) | |
{ | |
device = 'touch ' + device; | |
document.documentElement.className += ' ' + device; | |
} | |
window._device = device; | |
} | |
)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment