Better touchscreen detection in JS code (detect ipads)

Right now realmz’s touchscreen detection has some flaws mainly @Wasd cannot access the game since it does not recognize his iPad as a touchscreen device.

That’s why I propose this new boolean check:

var touch = window.matchMedia("(pointer: coarse)").matches; // true or false

This is used in the swordbattle.io source:

https://github.com/codergautam/swordbattle.io/blob/ccd5e199dc6f4106e9816244c1db63efa818f0a4/src/index.js#L50C14-L50C61

This script has been used in prod ever since launch and we never had any issues with it, @futurepear you may want to consider using something like this (detects if there is a “coarse” pointer meaning touchscreen).

Thanks!

3 Likes

Ye pls future i need gaem

Ich bin pro gamer

1 Like

Nice hope it comes though for you wasd

1 Like

Thanks

1 Like