Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable backspace and delete key with javascript in IE

Tags:

javascript

Anyone know how can I disable backspace and delete key with Javascript in IE? This is my code below, but seems it's not work for IE but fine for Mozilla.

onkeydown="return isNumberKey(event,this)"

function isNumberKey(evt, obj)
{

    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode == 8 || charCode == 46) return false;

    return true;
}
like image 923
Jin Yong Avatar asked Mar 20 '09 01:03

Jin Yong


People also ask

How do I turn off backspace delete?

Press the "Ins" key to toggle overtype mode off. Depending on your keyboard model, this key may also be labeled "Insert." If you simply want to disable overtype mode but keep the ability to toggle it back on, you are done.


1 Answers

This code cancels backspace action.

window.onkeydown = function (event) {

    if (event.which == 8) { 

         event.preventDefault();   // turn off browser transition to the previous page 

                 // put here code you need 

        }; 

};      
like image 182
Alexei Syrtsov Avatar answered Sep 25 '22 22:09

Alexei Syrtsov