faqts : Computers : Programming : Languages : JavaScript

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

18 of 20 people (90%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

Is it possible to detect and suppress the backspace key on my pages in IE?

Apr 8th, 2008 00:00
ha mo, Colin Fraser, Robert Nurse,


Yes it is poosible to detect any keystroke, and to supress it.  
This captures whatever keystroke you want to capture and lets you look 
at it values so you can see for yourself what keys do what. 
function capturekeyDown() {
	var keycode = event.keyCode
	var realkey = String.fromCharCode(event.keyCode)
	alert("keycode: " + keycode + "\nrealkey: " + realkey)
}
document.onkeydown = capturekeyDown
However, you may want to try this. This should cancel out the backspace 
in IE. 
function cancelBackspace(){  
  //substitute appropriate keycode ASCII numbers
  if (window.event.keyCode == 8) {
    // try to cancel the backspace
    window.event.cancelBubble = true;
    window.event.returnValue = false;
    return false;
  }
}
I have never had occasion to use this code, but it should work. 
For more information: 
This site provides a complete look at ASCII keycodes
http://www.asciitable.com/
This site proves a good explanation and Q&A about ASCII keycodes. 
http://www.jimprice.com/jim-asc.htm
Good luck.
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com