Created
June 6, 2016 11:45
-
-
Save framon/9fd7362ffbe08b082bde417d47a3eaa7 to your computer and use it in GitHub Desktop.
Prevent the backspace key from navigating back. (http://stackoverflow.com/questions/1495219/how-can-i-prevent-the-backspace-key-from-navigating-back)
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
// Prevent the backspace key from navigating back. | |
$(document).unbind('keydown').bind('keydown', function (event) { | |
var doPrevent = false; | |
if (event.keyCode === 8) { | |
var d = event.srcElement || event.target; | |
if ((d.tagName.toUpperCase() === 'INPUT' && | |
( | |
d.type.toUpperCase() === 'TEXT' || | |
d.type.toUpperCase() === 'PASSWORD' || | |
d.type.toUpperCase() === 'FILE' || | |
d.type.toUpperCase() === 'SEARCH' || | |
d.type.toUpperCase() === 'EMAIL' || | |
d.type.toUpperCase() === 'NUMBER' || | |
d.type.toUpperCase() === 'DATE' ) | |
) || | |
d.tagName.toUpperCase() === 'TEXTAREA') { | |
doPrevent = d.readOnly || d.disabled; | |
} | |
else { | |
doPrevent = true; | |
} | |
} | |
if (doPrevent) { | |
event.preventDefault(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment