Every other click on a link in Internet Explorer does not work

I noticed that when clicking a link in IE, where href is set to a javascript function, the first click will work, but the second click will sometimes not. The third will work, and the fourth will not. In other words, IE will run the javascript function only every time it is clicked. If you press a long pause between clicks, it will run the function every time. But as you click a little faster, it skips all the other clicks. Has anyone else noticed this behavior? I do not get the same behavior in Firefox.

Here is a sample code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Test</title> <script type="text/javascript"> var count = 0; function doClick() { count++; document.frm.COUNTER.value = count; } </script> </head> <body> <form name="frm" action=""> <input name="COUNTER" value="0"/> <a href="javascript:doClick();">Click Here</a> </form> </body> </html> 

Press very slowly and each time increases the counter. Click at least a more moderately fast pace and it skips clicks. This also happens with the onclick and onmousedown events of controls in IE6 / 7/8.

The reason this is a problem is because the application is a Point of Sale system, and we implement on-screen keys for the touch screen. If you press a button / button / key more than once because you are typing too fast, this will not be acceptable.

+4
source share
2 answers

Instead, you probably experience double clicks.

 <a href="" onclick="doClick();return false;" ondblclick="doClick();return false;"> 

That should do the trick.

+4
source

As far as I can tell, IE event handlers look slower than other browsers.

http://jsfiddle.net/F5B54/

I tested this in Firefox, Chrome, and IE8. IE definitely performed slower / missed clicks.

I don't have IE9, but it should be better than IE8.

--- Updated answer ---

IE handles onclick and dblclick separately. If you double-click twice, it will register as a single dblclick event.

Chrome, on the other hand, will log 2 onclick events and a dbl click event.

Mixing clicks and double-clicking for the same element can lead to significant behavior in different browsers.

+2
source

All Articles