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 windowwill 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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#