Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  150] [ 6]  / answers: 1 / hits: 56158  / 12 Years ago, wed, june 20, 2012, 12:00:00

Notice while on Google's homepage, with no focus on any element, pressing BACKSPACE will put the focus into the search toolbar instead of navigating back.



How can I accomplish this?



I keep running into this problem with users in my app. They don't have focus on any element and hit BACKSPACE which throws them out of the app.


More From » jquery

 Answers
39

I would bind an event handler to keydown and prevent the default action of that event if we're dealing with the backspace key outside of a textarea or input:



$(document).on(keydown, function (e) {
if (e.which === 8 && !$(e.target).is(input, textarea)) {
e.preventDefault();
}
});

[#84797] Monday, June 18, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
chase

Total Points: 78
Total Questions: 106
Total Answers: 93

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;