comments 9

Detect Touch Screen with JavaScript

We can detect touch screen with JavaScript let’s start it with creating a simple function ‘isTouchDevice();’ which will return true if its touch device.

function isTouchDevice(){
    return true == ("ontouchstart" in window || window.DocumentTouch && document instanceof DocumentTouch);
}

Now checking if ‘isTouchDevice();’ is returns true it means its a touch device.

if(isTouchDevice()===true) {
    alert('Touch Device'); //your logic for touch device
}
else {
    alert('Not a Touch Device'); //your logic for non touch device
}

Working Fiddle Example

Devices Supported:

Tested and verified on following devices;
1) IPhone 4s, IPhone 5
2) IPad, IPad mini
3) Samsung galaxy S5, Samsung Note 3
Works great on all mentioned devices and will work on other devices as well. Let me know in comments if you have tested and verified on other devices.