0

Is there a way in EmberJs to disable the backspace key, so it doesn't navigate back in the browser history?

Currently using EmberJs 2.0

I did find this possible answer:

https://stackoverflow.com/a/1235723/1913888

But one trick to this, is that a backspace action should work for example in an input box, but not for navigating back in the window history.

Thank you

Community
  • 1
  • 1
Aaron Lelevier
  • 19,850
  • 11
  • 76
  • 111

1 Answers1

2

In my app, I just listen for the keydown and check to see if it is triggered on the body.

$(window).on("keydown", function(evt){
    if (evt.keyCode===8 && evt.target.nodeName==="BODY") {
        evt.preventDefault();
    }
});

Other option is to check to make sure the target is not an input/content-editable.

epascarello
  • 204,599
  • 20
  • 195
  • 236
  • The code snippet looks good. I'm just wondering, how would you test this in Qunit for example? Also, where do you put the above snippet in your Ember App? Thank you for your help *epascarello* – Aaron Lelevier Jan 05 '16 at 18:37