When using a touch device such as an iPhone, iPad, or Android device, it can be challenging to accurately tap on small buttons with your finger. So far, there is no universal method in CSS media queries to detect touch devices. As a workaround, I check if the browser supports JavaScript touch events. An update: Recently, Chrome fixed a bug that previously enabled touch events for all devices, not just touch screens.
Here's the JavaScript function I use to determine if the browser supports touch events:
function isTouchDevice() {
return "ontouchstart" in window;
}
However, this method only checks for support of touch events by the browser, not necessarily the device itself.
Can anyone suggest the best way to enhance the user experience for touch devices without resorting to user agent sniffing?
While Mozilla has implemented a media query for touch-enabled devices, I have yet to come across similar solutions in other browsers: Mozilla Touch Media Query
Update: My goal is to avoid creating separate pages for mobile/touch users. The solution should involve detecting touch devices through object detection or similar methods in JavaScript, or implementing custom touch-specific CSS without relying on user agent detection. I reached out to the CSS3 working group after ensuring that the current possibilities are limited. Please respond only if you can meet these requirements in the question ;)