Javascript Key Handling And Browser Compatibility
Solution 1:
See the following pages, they will answer your quetions:
onkeydown event, onkeypress event, keyCode property, charCode property, which property
Solution 2:
The following article by Jan Wolter has never failed me and is far and away the best resource on browser key events I've seen: http://unixpapa.com/js/key.html. It answers all the questions you posed.
One thing to emphasize is that with careful use of the key event properties at your disposal you will almost certainly never need to sniff for a particular browser in your key handling code.
Solution 3:
2015 update:
According to MDNevent.charCode
, event.keyCode
and event.which
have all been deprecated. event.key
is the newest and hottest way to check which key has been pressed.
It looks easy to use, but browser support isn’t perfect. All we have now is partial support in Chrome 45+ (not out yet AFAIK), Firefox 23+ and IE 9+.
Post a Comment for "Javascript Key Handling And Browser Compatibility"