Is there a way to prevent the default action when the user clicks the backspace button in the browser? I don't need to keep the user from leaving, just because of the default backspace action. I need backspace to do something else (this is a game).
I tried without success:
window.addEventListener('keydown', function(e) { if (e.keyCode === Game.Key.BACK_SPACE) { e.preventDefault(); e.stopPropagation(); return false; } }, false);
If I put a warning inside if, a warning will appear for pressing the backspace key. So, keyCode is correct.
Edit: this should work in Opera 10.6, Firefox 4, Chrome 6, IE 9, and Safari 5.
javascript events
Tower 03 Oct 2018-10-10 15:46
source share