Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why/when do I have to tap twice to trigger click on iOS

Ok I feel like I'm crazy...

I'm looking at Mobile Safari on iOs 6.0. I can't seem to establish any rhyme or reason as to when tapping on an element will trigger click. In many cases, it seems I need to tap once to trigger a hover and then again to trigger a click.

The Mobile Safari spec says : "... The flow of events generated by one-finger and two-finger gestures are conditional depending on whether or not the selected element is clickable or scrollable... A clickable element is a link, form element, image map area, or any other element with mousemove, mousedown, mouseup, or onclick handlers... Because of these differences, you might need to change some of your elements to clickable elements..."

It goes on to suggest that the developer "...Add a dummy onclick handler, onclick = "void(0)", so that Safari on iOS recognizes the span element as a clickable element."

However, my testing has shown these statements to be false.

JsFiddle : http://jsfiddle.net/6Ymcy/1/

html

<div id="plain-div" onclick="void(0)">Plain Div</div> 

js

document.getElementById('plain-div').addEventListener('click', function() {    alert('click');  }); 

Try tapping the element on an iPad. Nothing Happens

But I digress. What is important to me is to find out the following question:

Exactly what are the criteria that determine when clicking on an element will fire a 'click' event on the first tap? As opposed to firing a 'hover' event on the first tap and a 'click' event on the second tap.

In my testing, anchor elements are the only elements that I can get to fire a click on the first tap, and then, only occasionally and inconsistently.

Here's where I start to feel crazy. I searched the internet far and wide and found next to nothing about this issue. Is it just me?! Does anybody know where there's been any discussion about the criteria for two-taps and or an approach to dealing with these limitations?

I'm happy to respond to questions/requests.

Thanks!

like image 932
user2383672 Avatar asked Jul 17 '13 21:07

user2383672


People also ask

Why do I have to tap everything twice on my iPhone?

If that changes, then you've unwittingly enabled VoiceOver, an accessibility feature on your iPhone. When enabled, your iPhone will speak menu items when you select them and require you to double-tap menus to open items. Disable VoiceOver to get back to business as usual on your iPhone.

Why do I have to press twice on IPAD?

All replies. A long shot, but check the AssistiveTouch setting in Accessibility in the General settings and see if that perhaps got turned on. If it's on, try turning it off. If not, try the usual steps: restart, reset, restore.


1 Answers

I had this same issue. The simplest solution is not to bind the mouseenter event on iOS (or any touch enabled target platform). If that is not bound the hover event won't get triggered and click is triggered on the first tap.

like image 76
Gareth Farrington Avatar answered Sep 28 '22 19:09

Gareth Farrington