Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
172
rated 0 times [  179] [ 7]  / answers: 1 / hits: 74318  / 14 Years ago, wed, may 26, 2010, 12:00:00

In an attempt to follow best practices, we're trying to use the proper JavaScript/jQuery events according to what device you are using. For example, we're building a mobile site that has an tag that will have an onclick or touch event. In the case of an iPhone, we'd like to use the touchstart event. We'd like to test if their device supports touchstart before we bind that handler to the object. If it doesn't, then we will bind onclick instead.



What is the best way to do this?


More From » jquery

 Answers
75

You can detect if the event is supported by:



if ('ontouchstart' in document.documentElement) {
//...
}


Give a look to this article:





The isEventSupported function published there, is really good at detecting a wide variety of events, and it's cross-browser.


[#96678] Sunday, May 23, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anyssaarielles

Total Points: 415
Total Questions: 107
Total Answers: 92

Location: Greenland
Member since Fri, Jul 31, 2020
4 Years ago
;