Last active
August 24, 2024 08:11
-
-
Save lunule/b8b0e8eb1eb1d5670bf6696ce3c87762 to your computer and use it in GitHub Desktop.
[JavaScript - Mobile Checkers] #collection #js #mobile #os
This file contains 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
/** | |
* VERSION 1 - DEVICE-SPECIFIC + GLOBAL | |
* ----------------------------------------------------------------------------------------------------- | |
*/ | |
const checkIphone = () => { | |
const u = navigator.userAgent | |
return !!u.match(/iPhone/i) | |
}, | |
checkAndroid = () => { | |
const u = navigator.userAgent | |
return !!u.match(/Android/i) | |
}, | |
checkIpad = () => { | |
const u = navigator.userAgent | |
return !!u.match(/iPad/i) | |
}, | |
checkMobile = () => { | |
const u = navigator.userAgent | |
return !!u.match(/Android/i) || !!u.match(/iPhone/i) | |
}; | |
/** | |
* VERSION 2 - GLOBAL, MOBILE OR NOT | |
* ----------------------------------------------------------------------------------------------------- | |
*/ | |
const isMobile = navigator | |
.userAgent | |
.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i) != null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment