createTouch vs ontouchstart - best way to detect touchscreen devices?
javascript, jquery, touch
Solution
`touchstart` event is fired when a touch point is placed on the touch surface([MDN][1])
`createTouch` method creates and returns a new Touch object.([MDN][2])
The better way from my point of view is detecting existance of event in window than only create it.
Also your statement check only for existing of touch events in window object, not touch screens, like windows phones, so probably you would like to check pointer-events too.
P.S.: Look at Modernizr library which have "touch" detection and much more.
Problem
Currently, for detecting touchscreen devices I use this in my javascript: ``` if ('createTouch' in document) { // do touchscreen-specific stuff } ``` I see that many developers use `ontouchstart`, like this: ``` if ('ontouchstart' in document) { // do touchscreen-specific stuff } ``` What is the difference between `createTouch` and `ontouchstart`? Which one is the safest to use? Are there some other simple, reliable alternatives to these two?