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?

46 of 107 people (43%) answered Yes
Recently 3 of 10 people (30%) 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!