Skip to content

Instantly share code, notes, and snippets.

@brianium
Created July 23, 2012 18:27
Show Gist options
  • Save brianium/3165240 to your computer and use it in GitHub Desktop.
Save brianium/3165240 to your computer and use it in GitHub Desktop.
is_mobile
function isMobileDevice()
{
var agent = navigator.userAgent.toLowerCase();
var otherBrowser = (agent.indexOf("series60") != -1) || (agent.indexOf("symbian") != -1) || (agent.indexOf("windows ce") != -1) || (agent.indexOf("blackberry") != -1);
var mobileOS = typeof orientation != 'undefined' ? true : false;
var touchOS = ('ontouchstart' in document.documentElement) ? true : false;
var iOS = (navigator.platform.indexOf("iPhone") != -1) ||
(navigator.platform.indexOf("iPad") != -1) ? true : false;
var android = (agent.indexOf("android") != -1) || (!iOS && !otherBrowser && touchOS && mobileOS) ? true : false;
if ( otherBrowser || mobileOS || touchOS || iOS || android ) return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment