Skip to content

Instantly share code, notes, and snippets.

@mteece
Created July 16, 2012 14:40
Show Gist options
  • Save mteece/3123080 to your computer and use it in GitHub Desktop.
Save mteece/3123080 to your computer and use it in GitHub Desktop.
Prevent BACKSPACE (requires jQuery).
// Prevent BACKSPACE
$(document).keydown(function(e) {
if (e.target.type !== 'textarea') {
var code = e.keyCode || e.which;
if (code === 8) { //BACKSPACE keycode
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = false;
//e.stopPropagation works only in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
return false;
}
}
});
@jlbruno
Copy link

jlbruno commented Jul 16, 2012

@brandonhenricks, fork, don't comment ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment