.keydown(function(e){
alert(e.keyCode);
...
This does return 8 as key of 'backspace' button. The problem though is the browsers sends be back in history!
This is the most annoying behaviour of windows browsers, I'm just trying to clear List box values with delete and backspace keys. I hate this behavior, and it's exactly the same in IE and in Chrome.
Any ideas I could make use of the backspace key?
Just use preventDefault()
:
$(document).keydown(function(e){
if ( e.keyCode == 8 ) e.preventDefault();
});
Note however that this will prevent the backspace to work in input fields. This could easily be remedied with the following:
$(document).keydown(function(e){
if ( e.keyCode == 8 && e.target.tagName != 'INPUT' && e.target.tagName != 'TEXTAREA') {
e.preventDefault();
}
});
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