I want my app to behave differently if it is being used in a touchscreen device (It'll run in the browser). Is there any JavaScript code that allows me to check that?
Asked
Active
Viewed 132 times
1 Answers
0
There are few properties in js which can help you
ontouchstart - An event which triggers when touching DOM elements.
maxTouchPoints - It's a read only property which returns the maximum number of touch points that device supports It can be used something like this
function isTouchScreen() {
return ( 'ontouchstart' in window )||( navigator.maxTouchPoints > 0 ) ||
}
isTouchScreen() will return True if it's touch screen. You can use react-device-detect if you want to have different functions for different devices if you're looking for this.

SobyDamn
- 91
- 1
- 4