Last Updated: February 25, 2016
·
1.147K
· francisc

Check for touch support

You can use this to check if the current User Agent supports touch.
For a more thorough check, look at the Modernizr implementation.

var hasTouch=!!('ontouchstart' in window);

2 Responses
Add your response

  1. expression 'ontouchstart' in window will return boolean value and it's not required to create boolean manualy (using !!)

  2. expression window.hasOwnProperty('ontouchstart') is faster :)

over 1 year ago ·

And window['prop'] even faster, but those two yield false.
The double negation is for clarity that it's a boolean.
Thanks for the comment.

over 1 year ago ·