Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent default action for tab key in chrome?

i want to PREVENT the default action when the tab key is pressed and only wanna do it in chrome, i can't find a solution for that, can anyone please help ?

i am using jquery

like image 559
Shaheer Avatar asked May 11 '11 08:05

Shaheer


People also ask

What does event preventDefault () do?

The preventDefault() method of the Event interface tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.

How can we prevent default behavior in react?

We can prevent this default behaviour by making a small modification to the definition of the handleSubmit function. We call a preventDefault on the event when submitting the form, and this will cancel the default event behavior (browser refresh) while allowing us to execute any code we write inside handleSubmit.


2 Answers

input.keydown(function(event){     if (event.keyCode === 9) {         event.preventDefault();     } }) 

On keyup is too late, you need to call the event on keydown. That worked for me.

like image 182
Ev Haus Avatar answered Oct 11 '22 07:10

Ev Haus


Here's an article on how to detect chrome: http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/

And this question: Disable tab key on a specific div might help you on disabling the tab key. If you are able to combine both yourself, you've probably got it working.

The disable function would become something like:

$('.textarea').on('keyup mouseup', function(e) {   if(e.which == 9) { e.preventDefault(); } }); 

e.which = 9 is the tab key according to the last link given. If you are able to wrap the browser detection around it yourself, I guess you've got your working example.

like image 44
Joshua - Pendo Avatar answered Oct 11 '22 07:10

Joshua - Pendo