Created
August 14, 2015 10:09
-
-
Save rolia17/c86bdb3ecf75ee642be8 to your computer and use it in GitHub Desktop.
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