Created
March 11, 2022 00:07
-
-
Save gdibble/1fc987aa55bdcb8c2f5aafe551492a70 to your computer and use it in GitHub Desktop.
Mobile Device Feature Detection (Works in Chrome + Safari as of 2022-02-07)
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
/** isMobile - Feature Detection of an actual mobile device | |
* @description The localStorage.mobile works in Chrome mobile; the latter works in Safari mobile. | |
* Does not trigger desktop browsers with or w/o the dev-tools open and/or on a mobile simulator. | |
* @see https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser/71030087#71030087 | |
*/ | |
const isMobile = localStorage.mobile || window.navigator.maxTouchPoints > 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried putting this in a util, e.g.
isMobile.js
and returning the value, but it only worked as aconst
🙏 Simple ask: If you 👍, please upvote the SO post so more people can find and use the code. TY!