Skip to content

Instantly share code, notes, and snippets.

@mediamichael
Created September 17, 2013 22:31
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 mediamichael/6601585 to your computer and use it in GitHub Desktop.
Save mediamichael/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