Skip to content

Instantly share code, notes, and snippets.

@lunule
Last active August 24, 2024 08:11
Show Gist options
  • Save lunule/b8b0e8eb1eb1d5670bf6696ce3c87762 to your computer and use it in GitHub Desktop.
Save lunule/b8b0e8eb1eb1d5670bf6696ce3c87762 to your computer and use it in GitHub Desktop.
[JavaScript - Mobile Checkers] #collection #js #mobile #os
/**
* 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