javascript - backspace working in firefox after the alert windows is shown even if e.preventdefault() is used -


i need disable backspaces webpages in project , have done using e.prevent default method, when alert shown e.prevent default not working ,the webpage goes previous page when pressed backspace. 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 called everytime press backspace key not working when i'm on alert window. above backspace code included jsp page webpages.

add prevent backspace code on $(document).keydown.

it occur on complete document, regardless of alert or popup open.

$(document).keydown(function(e) {              if (e.keycode == 8) alert('not allowed');     }); 

jsfiddle demo


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -