I just opposed this annoyance and found this question in the search for answers, so here are the details of my research and solution (well, a workaround).
The keyup and keydown simply will not fire on the input or textarea elements in the Blackberry browser when the backspace key is pressed. This will, however, fire when the event handler is bound to document :
$("#myInput").keydown(someFn); //Will not fire for backspace $(document).keyup(someFn); //Will fire for backspace
Why this is so, I have no idea. The keyup event should bubble up, and this happens, but since it doesn't even fire when you press the backspace key, that is not much.
However, we have another event at our disposal. The input event is supported by the Blackberry browser and correctly fires at any time when the value of an element changes (including, fortunately for us, when this change occurs due to pressing the backspace key).
Thus, we can solve the problem by binding event handlers to keydown and input . The keydown event will fire before input , unless the backspace key is pressed, in which case keydown will not fire. Therefore, we can easily track this:
function handler(e) { if (e.keyCode === 8) { alert("Backspace!"); //Backspace was pressed :) } } var elem = document.getElementById("example"); elem.addEventListener("keydown", function (e) { //Bind to keydown event this.keydownFired = true; //Remember that keydown fired in expando property handler.call(this, e); //Call the event handler }, false) elem.addEventListener("input", function (e) { //Bind to input event if (!this.keydownFired) { //Keydown didn't fire, must have pressed backspace e.keyCode = 8; //Fix the event object handler.call(this, e); //Call the event handler } delete this.keydownFired; //Clean up so we can handle next key press }, false);
Some notes:
As far as I can tell, this is only a problem in the browser on Blackberry 6. I tested Blackberry 5 (physical device and simulator) and 7 (simulator), and both will trigger keydown and keyup events for the backspace keyword.
This “fix” works in almost every browser in which I tested it (so you can use it to properly support Blackberry 6 without breaking other browsers), except Opera Mobile (tested in version 12), which for some people like to run twice input event.
This allows you to detect a backpressure when text is entered at a delete (otherwise, the input event does not fire). This is probably the biggest fall script.
You can find a working example here, but to test a mobile device, it loads the embedded version faster.
James allardice
source share