[Javascript] Re: controlling the backspace key

Bill Marriott bill.marriott at optusnet.com.au
Sun Nov 24 03:45:25 CST 2002


Hi Everyone,

The following code traps the key stroke "backspace" in a web form so that
the user can't navigate back to the last page.
However I would like to engage the function only when the user is not in a
form element.
Does anyone know what code I should use?
Thanks
Bill Marriott

function mykeyhandler() {
  if (window.event && window.event.keyCode == 8) { // try to cancel the
backspace
     window.event.cancelBubble = true;
     window.event.returnValue = false;
     return false;
  }
}

document.onkeydown = mykeyhandler;








More information about the Javascript mailing list