Detect touch events on all major mobile platforms
Modernizr doesn't currently detect touch events in Windows (Phone) 8.
So, instead you can easily detect touch on iOS, Android, BlackBerry, Bada and Windows (Phone) 8 with the following:
var html = document.documentElement,
supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints;
if (supportsTouch)
html.className += ' touch';
else
html.className += ' no-touch';
}
This will allow you test for touch support in both JavaScript and CSS.
I've got this wrapped up in a little JavaScript plugin, too: https://github.com/izilla/Supports-Touch
Written by Matt Stow
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Css
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#