I use jQuery preventDefault on a keydown event: http://jsbin.com/ixaqok/edit#javascript,html When running the example code in Firefox and Opera the keypress event still is fired, but in Chrome, IE8 and Safari it's not.
Why? Is preventDefault not supposed to work the same in all browsers?
Thanks!
The problem is that unlike other browsers, Opera only allows you to suppress the default behaviour of keystrokes in the keypress
event, not the keydown
event. Therefore the solution is to use the keypress
event instead.
For more details, use what I consider the definitive page on the mess that is browser key events: http://unixpapa.com/js/key.html. Suppressing default key behaviour is section 2.3.
Opera has problem with recognizing and resolving keydown (and some other key releated funcitons)
see:
http://www.quirksmode.org/dom/events/keys.html
http://api.jquery.com/event.preventDefault/ (in discussion)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With