In Chrome, it works the first time, and in Firefox from the 2nd time, why? How can I fix this so that in all browsers it works the first time?

$(document).on('keyup', function( event ) { if(event.keyCode === 27) { alert('Esc key pressed.'); } }); 
  • It works for me in Firefox the first time, try updating the browser, cleaning the hash and debugging about the hash. - Yaroslav Zaika
  • You need to watch all the code. I had a problem with Firefox, the key presses did not work after I turned off the work of some keys with the "disable" mode. I had to turn off the function. I don’t know how it works for them, but you need to look for the error in the remaining parts of the code - ALexander
  • Version ff? I can not play. Plus, as noted above, if you have an error manifested in the working code and not in the minimal example, there are a lot of nuances. For example, included autocompet as one of the pieces that came to my head. - Duck Learns to Take Cover

1 answer 1

Try:

 $(document).keypress(function( event ) { if((event.keyCode ? event.keyCode : event.which) == 27) { alert('Esc key pressed.'); return false; } }); 

https://stackoverflow.com/questions/7996449/jquery-keyup-working-in-all-browsers-except-firefox

  • also from the 2nd time - Radick
  • after exiting full-screen mode does not work immediately, in normal mode, yes, it works - Radik