Skip to content

Instantly share code, notes, and snippets.

@thommorais
Created February 15, 2018 20:54
Show Gist options
  • Select an option

  • Save thommorais/ff02d01cee18a2cc789713de56d8a29b to your computer and use it in GitHub Desktop.

Select an option

Save thommorais/ff02d01cee18a2cc789713de56d8a29b to your computer and use it in GitHub Desktop.
Detecting Mobile Devices with JavaScript
const isMobile = {
Android: _ => navigator.userAgent.match(/Android/i),
BlackBerry: _ => navigator.userAgent.match(/BlackBerry/i),
iOS: _ => navigator.userAgent.match(/iPhone|iPad|iPod/i),
Opera: _ => navigator.userAgent.match(/Opera Mini/i),
Windows: _ => navigator.userAgent.match(/IEMobile/i),
any: _ => isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment