Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created May 26, 2010 15:09
Show Gist options
  • Save cowboy/414610 to your computer and use it in GitHub Desktop.
Save cowboy/414610 to your computer and use it in GitHub Desktop.
Disable backspace in non-form elements
// Disable backspace in non-form elements in Chrome
// TODO: add input type, disabled and element contenteditable checks
(function(window){
window.addEventListener( 'keydown', handler, true );
window.addEventListener( 'keypress', handler, true );
function handler(e) {
!/^(?:textarea|input)$/i.test( e.target.nodeName ) && e.keyCode == 8 && e.preventDefault();
};
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment