Faqts : Computers : Programming : Languages : JavaScript : Event handling

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

52 of 115 people (45%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How to trap backspace button event and trap it if the focus is in not inside a text field /text area

Jun 27th, 2003 09:27
Kasey, Mohan B,


You can trap the backspace button using this short piece of code. 
<script type="text/JavaScript" language="JavaScript">
<!--
function disablebackspace() {
  if (window.focus) window.focus();
  document.onkeydown=catchbackspace;
  document.onkeyup=catchbackspace;
}
function catchbackspace() {
  if (!e) e=window.event;
  if (e.keyCode==8){
    alert("Backspace key was pressed.");
    return false;
  }
}
// -->
</script>
Good luck!