Last active
October 23, 2018 19:14
-
-
Save 0xch4z/b134e1fd2ff29345f7f24c8081af28b8 to your computer and use it in GitHub Desktop.
Useful snippet to test if a devices has a touch screen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const isTouchScreenDevice = () => { | |
| try { | |
| window.document.createEvent('TouchEvent'); | |
| // if can create touch event without error | |
| // the device has a touch screen | |
| return true; | |
| } catch (err) { | |
| // swallow error and return false | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment