views:

346

answers:

6

Backspace is the browser hotkey for Navigate Back To The Last Page. I know that when an input has the focus this hotkey is disabled. But I have keyup and keydown events binded to this input, and something I wrote is causing this trouble.

Do you know the solution?

+1  A: 

when you have handled the event from the input element, cancel that event's bubbling before returning.

kennebec
both event.preventDefault() or event.stopPropagation() solves the problem on IE and Chrome. But I still haven't found the solution for Firefox http://www.quirksmode.org/js/events_order.html
Jader Dias
A: 

The problem was caused by the input removal before returning the onKeyDown event.

Jader Dias
A: 

try this on you onKeyDown or onKeyPress even

if (event.keyCode==8)//where 8 ascii code of backspace { retunr; }

xavoDev
A: 

You can try to hook into window.onbeforeunload event to prevent such accidental navigation.

Marcin
A: 

That you can make:

  1. You can set a listener for InputField and look all keydown events.
  2. In event listener you can make a buffer variable, which have a real InputField value.

So, if you accept a not Backspace code then new value of buffer will be InputField value and you make use your hotKeyFunction, else new value of InputField will be buffer value and you get a normal working of InputField.

+1  A: 

I had a similar need i.e. to neutralize the Back action caused by Backspace key and I came across a solution on this site

http://www.webmasterworld.com/javascript/3785986.htm

I hope it will help you.