How to determine if the client is a touch device [duplicate] How to determine if the client is a touch device [duplicate] jquery jquery

How to determine if the client is a touch device [duplicate]


You can use the following JS function:

function isTouchDevice() {   var el = document.createElement('div');   el.setAttribute('ongesturestart', 'return;'); // or try "ontouchstart"   return typeof el.ongesturestart === "function";}

Source: Detecting touch-based browsing.

Please note the above code only tests if the browser has support for touch, not the device.

Related links:

There may be detection in jquery for mobile and jtouch


Include modernizer, which is a tiny feature detection library. Then you can use something like below.

if (Modernizr.touch){   // bind to touchstart, touchmove, etc and watch `event.streamId`} else {   // bind to normal click, mousemove, etc}


if ("ontouchstart" in document.documentElement){  alert("It's a touch screen device.");}else{ alert("Others devices");}

most simple code i found after browsing a lot here and there