Is there a way to check if the device type is touch screen?

Hi there!

I am currently using formFactor (wixWindowFrontend). I note the comment “Some tablet devices, such as iPads, are identified in this property as “Desktop”.

May I ask if there is a way to reliably if the device type is touch screen or not? Something like navigator.maxTouchPoints?

Thanks!

Not natively, but a creative solution could be sending an HTTP request to a service that echoes the user-agent, like https://httpbin.org/user-agent for example

import { fetch } from 'wix-fetch'
fetch('https://httpbin.org/user-agent')
    .then(res => {
        res.json()['user-agent']
        return /Mobile|Android|iPhone|iPad|Touch/i.test(agent)
    })

Something like this might help, though it could also complicate things, having to consider every possible touchscreen device’s user-agent

Thanks Dean! That’s helpful.

The only other concern I have other than the added complication is the user-agent reduction / deprecation which makes this method less effective going forward.

1 Like

Huh! This is the first I’m hearing about the deprecation to be honest

This will indeed be problematic in the future, like a cat-and-mouse game, with browsers trying to keep their users confidential

Perhaps navigator could be used when embedding custom code in the <head>