Skip to content

Instantly share code, notes, and snippets.

@gdibble
Created March 11, 2022 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdibble/1fc987aa55bdcb8c2f5aafe551492a70 to your computer and use it in GitHub Desktop.
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)
/** 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;
@gdibble
Copy link
Author

gdibble commented Mar 11, 2022

WORKS IN CHROME + SAFARI as of 2022-02-07

I tried putting this in a util, e.g. isMobile.js and returning the value, but it only worked as a const


🙏 Simple ask: If you 👍, please upvote the SO post so more people can find and use the code. TY!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment