Last active
March 9, 2021 02:15
-
-
Save cstephe/1ef2c48b136589935853 to your computer and use it in GitHub Desktop.
Angular directive: prevent backspace from acting like the back button
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
.directive('backSpaceNotBackButton', [function(){ | |
return { | |
restrict: 'A', | |
link: function(scope, element, attrs){ | |
// This will stop backspace from acting like the back button | |
$(element).keydown(function (e) { | |
var elid = $(document.activeElement) | |
.filter( | |
"input:not([type], [readonly]),"+ | |
"input[type=text]:not([readonly]), " + | |
"input[type=password]:not([readonly]), " + | |
"input[type=search]:not([readonly]), " + | |
"input[type=number]:not([readonly]), " + | |
"input[type=email]:not([readonly]), " + | |
"input[type=date]:not([readonly]), " + | |
"input[type=datetime]:not([readonly]), " + | |
"input[type=datetime-local]:not([readonly]), " + | |
"input[type=month]:not([readonly]), " + | |
"input[type=tel]:not([readonly]), " + | |
"input[type=time]:not([readonly]), " + | |
"input[type=url]:not([readonly]), " + | |
"input[type=week]:not([readonly]), " + | |
"textarea")[0]; | |
if (e.keyCode === 8 && !elid) { | |
return false; | |
} | |
}); | |
} | |
} | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
could you please explain how to use. i am new in angulrjs
thanks in advance
AKD