Skip to content

Instantly share code, notes, and snippets.

@make-sum
Created September 17, 2013 22:31
Show Gist options
  • Save make-sum/6601585 to your computer and use it in GitHub Desktop.
Save make-sum/6601585 to your computer and use it in GitHub Desktop.
Detect if device is Android, iPhone, iPad, or iPod.
var isMobile;
var is_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent);
var is_safari_or_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent);
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf( "android") > -1;
if ( isAndroid || is_uiwebview || is_safari_or_uiwebview ) {
isMobile = true;
//do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment