Created
March 2, 2013 07:06
-
-
Save kyleweiner/5070007 to your computer and use it in GitHub Desktop.
jQuery: A jQuery function to detect mobile devices.
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
/** | |
* @function isMobile | |
* @description a jQuery function to detect mobile devices | |
* @param userAgents [array] | |
* @return object | |
*/ | |
var userAgents = ['iPad', 'iPhone', 'Android', 'IEMobile', 'BlackBerry']; | |
function isMobile(userAgents) { | |
var userAgent, | |
isMobile = { | |
any: false | |
}; | |
$.each(userAgents, function (index) { | |
userAgent = userAgents[index]; | |
isMobile[userAgent] = navigator.userAgent.toLowercase().indexOf(userAgent.toLowercase()) > -1; | |
if (isMobile[userAgent]) isMobile.any = true; | |
}); | |
return isMobile; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Typo in toLowercase()
Should be toLowerCase()
Also I'd move
var userAgents =
insidefunction isMobile() { }
Also it does not detect Android Tablet