Skip to content

Instantly share code, notes, and snippets.

@wkw
Created June 25, 2016 15:52
Show Gist options
  • Save wkw/4d8a533193bc032ee0eaab94bd64f0d8 to your computer and use it in GitHub Desktop.
Save wkw/4d8a533193bc032ee0eaab94bd64f0d8 to your computer and use it in GitHub Desktop.
Detect mobile devices by presence of touch handlers.
// https://hacks.mozilla.org/2013/04/detecting-touch-its-the-why-not-the-how/
if (('ontouchstart' in window) ||
(navigator.maxTouchPoints > 0) ||
(navigator.msMaxTouchPoints > 0)) {
/* browser with either Touch Events of Pointer Events
running on touch-capable device */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment