keyPressed() and BACKSPACE in browser

When the user presses the BACKSPACE key, it does indeed shorten the word, but then immediately calls the browser BACK button. How do I avoid this?

function keyPressed() {

if (keyCode == BACKSPACE) {





  • edited May 2016

    Much probably we can't, given there are browsers which hardwire BACKSPACE key for that functionality.

    Most we can do is give the users some alternative keys: :-<

    function keyPressed() {
      const k = keyCode;
      if (k == BACKSPACE | k == LEFT_ARROW)  shorten(word);
  • The only place you can expect backspace to work as expected in a browser is in a text field. You may find ways to block the default backspace behaviour; but these are essentially hacks and non-standard/badpractice: i.e. may work/break from browser to another...

Sign In or Register to comment.