How to check browser for touchstart support using JS/jQuery? How to check browser for touchstart support using JS/jQuery? javascript javascript

How to check browser for touchstart support using JS/jQuery?


You can detect if the event is supported by:

if ('ontouchstart' in document.documentElement) {  //...}

Give a look to this article:

The isEventSupported function published there, is really good at detecting a wide variety of events, and it's cross-browser.


Use this code to detect if the device supports touch.

Also work for windows 8 IE10 which uses 'MSPointerDown' event instead of 'touchmove'

var supportsTouch = false;if ('ontouchstart' in window) {    //iOS & android    supportsTouch = true;} else if(window.navigator.msPointerEnabled) {    // Windows    // To test for touch capable hardware     if(navigator.msMaxTouchPoints) {        supportsTouch = true;    }}


You could check if typeof document.body.ontouchstart == "undefined" to fall back to normal dom events