How to disable the function of ESC key in JavaScript?
dom-events, javascript
Solution
I got the solution to control the " F5 , Esc , BackSpace(BS) " keys with the following code.
My Java Script code will be ,
document.attachEvent("onkeydown", win_onkeydown_handler);
function win_onkeydown_handler() {
switch (event.keyCode) {
case 116 : // 'F5'
event.returnValue = false;
event.keyCode = 0;
break;
case 27: // 'Esc'
event.returnValue = false;
event.keyCode = 0;
break;
case 08: // 'BackSpace'
if (event.srcElement.tagName == "INPUT"
|| event.srcElement.tagName == "TEXTAREA") {
} else {
event.returnValue = false;
event.keyCode = 0;
}
break;
}
}
Thanks who are all supported me to do this and for your suggestions.
Problem
In my chat application there are some text fields which gets the user login details. When filling the user details, if a user suddenly pressed the ESC key, the data will be lost. If need to disable the function of ESC key, which event I need to use? How can I do that. My JavaScript code is: ``` function esc(e){ e = e || window.event || {}; var charCode = e.charCode || e.keyCode || e.which; if(charCode == 27){ return false; } } ``` I searched a lot in Stack Overflow and Google; nothing worked. Please, can anyone help me to do that?