How can I detect when the "Enter" key is pressed in the window, and conditionally suppress it? I've found lots of solutions with jQuery and MooTools, but not a frameworkless version. Thanks!
you do that by adding a function to the onkeypress event of your documents body.
document.onkeypress = function (event) {
event = event || window.event;
if (event.keyCode === 13) {
alert('Enter key pressed');
return false;
}
return true;
}
To suppress any further action you'll have to return false at the end of the function.
Best wishes, Fabian
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