Onclick Event Sometimes Does Not Fire (IE6 / IE7 / IE8)

I noticed that sometimes IE6 / IE7 / IE8 do not always trigger onclick events (from buttons when pressed). It seems that the grace period a couple of seconds after the last onclick event was fired.

I decided to test this behavior using this code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <script type="text/javascript"> window.onload = function(){ document.getElementById('clicker').onclick = function(){ var i = 0 return function(){ i+= 1 this.value = i.toString() } }() } </script> </head> <body> <input type="submit" value="click here" id="clicker"/> </body> </html> 

Comparison of the browser (with a speed of 1/4) As you can see, to trigger an event on IE 6-8, it takes about two clicks of a button, while for 9 / firefox / chrome, the event fires every time.

What could be the reason for this? IE6 and 8 were tested on a virtual machine (VirtualBox) with Windows XP.

Other:

  • I had the same results with 'submit' and 'button'.
  • Using "Onmouseup" as an alternative to onclick seems to work.
+4
source share
1 answer

In versions of older versions of IE, you must handle both Click and Double-click.

If you do not, only the first click of your double-click will be processed, which will give you this illusion.

Try the following:

 window.onload = function() { var i = 0; document.getElementById('clicker') .onclick = function() { this.value = (i+=1).toString() }; document.getElementById('clicker') .ondblclick = function() { this.value = (i+=1).toString() }; } 
+2
source

Source: https://habr.com/ru/post/1480355/


All Articles