Referring to Chrome\'s ability to emulate device resolution and touch events: https://developer.chrome.com/devtools/docs/device-mode
The actual issue:
You need to check for ontouchstart
in window. Not document.documentElement.
Touch Events are to be detected with:
'TouchEvent' in window && 'ontouchstart' in window
I should mention that I am not including the window.DocumentTouch
method used by Modernizr. It's only for Firefox < 25 and Mozilla dropped the Touch Metro UI on Windows. So I don't see any plausible or relevant browser usage to really justify it any longer. And while TouchEvent in window
isn't required, I think it's more future proof and technically correct to check the API's presence too.
For more details on Touch Events detection see the latest Modernizr Touch Event Feature Detect with link and references in comments.