Disabling the backspace key on a page with jQuery
Submitted by David Lohmeyer on November 18, 2010 - 12:10pm
I had an issue with a multi-page form recently where Internet Explorer would go back a page immediately upon hitting the backspace key. If you accidentally do this while not in a text field you'll lose your form data. Other browsers actually ask you if you want to resend data when you go back. The solution was to disable the backspace key on my form page. I accomplished this with the following Javascript (requires jQuery):
$(document).keydown(function(e) { var element = e.target.nodeName.toLowerCase(); if (element != 'input' && element != 'textarea') { if (e.keyCode === 8) { return false; } } });
Your backspace key will still work while typing in textarea and input form elements.
Related Posts
Monthly archive
- April 2013 (2)
- February 2013 (1)
- January 2013 (1)
- October 2012 (1)
- August 2012 (2)
- July 2012 (1)
- June 2012 (5)
- May 2012 (3)
- April 2012 (2)
- March 2012 (1)