Created
May 26, 2010 15:09
-
-
Save cowboy/414610 to your computer and use it in GitHub Desktop.
Disable backspace in non-form elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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