I need to disable backspaces for all webpages in my project and i have done it using e.prevent default method, but when an alert is shown the e.prevent default is not working ,the webpage simply goes to the previous page when pressed backspace. Any solutions ?
if(input){
alert("wrong input");
}
function disableBackSpace(e){
var doPrevent = false;
if (e.keyCode === 8) {
var d = e.srcElement || e.target;
if ((d.tagName.toUpperCase() === 'INPUT' &&
(
d.type.toUpperCase() === 'TEXT' ||
d.type.toUpperCase() === 'PASSWORD' ||
d.type.toUpperCase() === 'FILE' ||
d.type.toUpperCase() === 'SEARCH' ||
d.type.toUpperCase() === 'EMAIL' ||
d.type.toUpperCase() === 'NUMBER' ||
d.type.toUpperCase() === 'DATE' )
) ||
d.tagName.toUpperCase() === 'TEXTAREA') {
doPrevent = d.readOnly || d.disabled;
}
else {
doPrevent = true;
}
}
if (doPrevent) {
e.preventDefault();
}
}
The above method is called everytime i press a backspace key but this is not working when i'm on a alert window. Basically the above backspace code is included as a jsp page for all webpages.