Created
February 15, 2018 20:54
-
-
Save thommorais/ff02d01cee18a2cc789713de56d8a29b to your computer and use it in GitHub Desktop.
Detecting Mobile Devices with JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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