2

As Firefox users will know, when pressing the backspace button without selecting an input field will make you return to the previous tab.

Problem is, I have made an input field based on document.onkeydown(data){k=(data.key)} data. Users do not have to click this field to use it.

When I press backspace into my input field, Firefox goes back to the previous tab. Very annoying.

This works fine in Internet Explorer and Google Chrome.

Anyone knows how to stop Firefox from going back to the previous page when pressing backspace WITHOUT other interactions of the user?

JScoder
  • 25
  • 5
  • You probably already tried this, but can you confirm that event.preventDefault() and event.stopPropagation() won't work ? – Logar Mar 14 '18 at 15:42

1 Answers1

0

Just tried this one in firefox and it seems to work :

window.document.addEventListener('keydown', e => {
  if(e.keyCode === 8) {
    e.preventDefault();
    e.stopPropagation();
    //Put some logic to simulate backspacke key in your input content here
  }
})
Logar
  • 1,248
  • 9
  • 17
  • This exact solution stops my program from loading on IE, but it works on Firefox and Google Chrome. I'll probably figure it out from here, thanks! - UPDATE: implemented it with document.onkeydown=function(d){k=(d.key); d.preventDefault(); d.stopPropagation(); – JScoder Mar 15 '18 at 07:52