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);
Written by Francisc Romano
Related protips
2 Responses
expression
'ontouchstart' in window
will return boolean value and it's not required to create boolean manualy (using!!
)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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Touch
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#