Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
71
rated 0 times [  76] [ 5]  / answers: 1 / hits: 49581  / 13 Years ago, tue, june 7, 2011, 12:00:00

is there any nice and clean method or trick to find out if the user is on a touch-device or not?



I know there is stuff like
var isiPad = navigator.userAgent.match(/iPad/i) != null;



but I simply wonder if there is a trick to generally determine if the user is on Touch device?
Because there are a lot more touch devices and tablets out there then just iPads.



thank you.


More From » jquery

 Answers
87

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


[#91839] Saturday, June 4, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sonja

Total Points: 541
Total Questions: 113
Total Answers: 114

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
sonja questions
Mon, Nov 30, 20, 00:00, 4 Years ago
Sun, Oct 11, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
Sun, Nov 10, 19, 00:00, 5 Years ago
Mon, Aug 26, 19, 00:00, 5 Years ago
;