Skip to content

Instantly share code, notes, and snippets.

@rolia17
Created August 14, 2015 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolia17/c86bdb3ecf75ee642be8 to your computer and use it in GitHub Desktop.
Save rolia17/c86bdb3ecf75ee642be8 to your computer and use it in GitHub Desktop.
Detect mobile devices
/**
* @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