Typing the tab character in browser text boxes

89

23

A lot of the time, when I want to format text within a web page's text box I'll hit the Tab key.

Unfortunately, that doesn't insert the tab character but instead moves the control to the next form element (like a button or a check box).

For browsers like Firefox/IE, is there a way to get the formatting behavior of a tab, within a text box, by typing a key combination?

Rohit

Posted 2009-11-09T14:32:17.857

Reputation: 1 299

Answers

9

Tabinta is a Firefox add-on that lets you do this.

invert

Posted 2009-11-09T14:32:17.857

Reputation: 4 918

It's not compatible with Firefox anymore. – rory.ap – 2018-11-05T15:02:10.277

This is a plugin that works in Firefox 64: https://addons.mozilla.org/en-US/firefox/addon/textarea-tabbing/

– Stefan_Fairphone – 2019-01-09T22:21:06.033

1This plugin no longer exists (at no fault of the answer, it has been nearly a decade since the question was answered and Firefox has changed a lot). – aoeu – 2019-04-15T13:23:13.337

Noted @aoeu. I flagged the answers for deletion as per https://meta.stackexchange.com/a/11706/152063

– invert – 2019-05-15T06:06:17.710

4Any solution for Chrome? – sorin – 2012-03-16T14:47:28.620

2@SorinSbarnea: See my answer – Janus Troelsen – 2014-01-20T12:13:45.227

63

In Windows, you can push Alt+09. This only works with the number pad number keys. (Release Alt after pressing the last number key.)

ta.speot.is

Posted 2009-11-09T14:32:17.857

Reputation: 13 727

Sadly no longer working FF 36.0.1 on Windows. – MZB – 2015-03-14T18:18:39.193

4Be sure you are using the NumPad keys – CatamountJack – 2010-03-17T00:30:32.697

@Chris: When I follow those exact instructions, it doesn't insert a tab character, but acts like the tab key. Did you try this in a web browser? – Casebash – 2010-04-09T04:39:43.410

@Casebash It works in this very comment window, in Chrome, in Windows 7 x64. – Chris – 2010-04-25T15:27:25.957

While this works in many applications, it does not work on IE 11/Windows 8. – Moby Disk – 2016-12-05T22:12:49.190

Tested and works in Chrome 59.0.3071.115, Windows 10 Pro. Best answer in my point of view, and easy to remember. tab Thanks! – Kai Noack – 2017-07-14T08:53:39.097

2Only if you have Windows and a keyboard with a numpad. – Mechanical snail – 2011-10-11T04:15:57.417

1... and if you are using Chrome. FF sees it like the tab key, IE doesn't seem to do anything. Again, +1 for reminding this simple olden hack :) – Halil Özgür – 2011-12-18T17:48:04.937

@Chris, I don't think you need to release Alt until you've pressed all of the numbers. – Sam – 2013-06-13T01:19:12.773

This does not work for me in FF. – Pedro77 – 2014-02-28T13:39:29.090

51

Linux and other POSIX systems (except Mac OS):

To input tabs in GTK+ applications (like Firefox or Chrome):

  1. Ctrl + Shift + U

  2. Type 9

  3. Press Space or Enter

Source: Wikipedia: Unicode Input

Janus Troelsen

Posted 2009-11-09T14:32:17.857

Reputation: 1 958

It works but not useful for indenting multiple lines at once. – MYGz – 2016-12-27T05:17:35.137

13

In Safari and Firefox on Mac OS X, you can press ControlOptionTab to insert a tab in the text field you're currently editing.

Daniel Beck

Posted 2009-11-09T14:32:17.857

Reputation: 98 421

7Looks like this doesn't work in Chrome 50 on El Cap – jcollum – 2016-05-23T15:24:01.477

1Nor on Firefox 53 on Sierra. – Jason R. Coombs – 2017-05-25T16:25:33.247

1@JasonR.Coombs Still works in Safari, so it's safe to assume something changed in Firefox in the four years since I wrote this answer. – Daniel Beck – 2017-05-25T18:30:01.257

10

Open Notepad or similar text editor, and start a new blank document. Type Tab. Copy your tab character to the clipboard. (On Windows, Ctrl+A, Ctrl+C will do this).

Now switch back to the textarea in your browser. Position the cursor where you want it, and paste the tab character. (Ctrl+V on Windows).

Voila, done!

Doin

Posted 2009-11-09T14:32:17.857

Reputation: 201

1Ciro, is it broken for regular textboxes and text input fields, or just "contenteditable" elements? Because if it's just a problem for "contenteditable", it might not affect that many people (the OP for example)... – Doin – 2015-08-01T12:46:07.467

2This was the simplest solution, unless you need to do this frequently. – jcollum – 2016-05-23T15:33:11.070

8

There is a Chrome plugin called Textarea Code Formatter.

It allows you insert tabs into text boxes in the Chrome browser. It also allows you to highlight multiple lines and insert tabs before each selected line.

However, an issue is that often you want standard tab insertion behaviour. If you do use tab to toggle between boxes, then you may to select "disabled" by default in the options.

Jeromy Anglim

Posted 2009-11-09T14:32:17.857

Reputation: 642

4

If it's your site:

jQuery plugin: http://teddevito.com/demos/textarea.html

jQuery(document).ready(function () {

     $("textarea").tabby();

});

Load jQuery and the plugin first, then you can tab and make a tab, and shift+tab to "untab" as it were.

For browser-wide support, you will have to use an extension, userscript, plugin, etc. like: 46704 for Greasemonkey.

Grizly

Posted 2009-11-09T14:32:17.857

Reputation: 866

The link is dead. What's with all this jQuery stuff. There's got to be a way to accept tabs using plain JavaScript. The jQuery plugin is always nice for an already-implemented solution, but it's not really the solution. – Triynko – 2014-04-22T22:17:52.217

Try this chief: http://stackoverflow.com/a/13130

– Grizly – 2014-04-23T02:15:32.113

1

I've messed wit AutoHotkey a bit to get this ability, and the only 'bulletproof' solution I found is really to paste (not send) the tab character itself.

;
; TAB character
; pasted from clipboard
; win tab
;
#tab::
old_clip:=clipboard
clipboard:=A_Tab
clipWait
sendInput,^v
clipboard:=old_clip
clipWait
return

It turns out that this AHK bind is even useful in text editors that handles the TAB keystroke extra; eg. IDE configured to use autoindent-by-spaces.

myf

Posted 2009-11-09T14:32:17.857

Reputation: 451

1

The big advantage of Tabinta in Firefox is that you can map the tab character to another hotkey, since you really don't want to lose the tab key default behavior in the browser.

With Internet Explorer you have no solution in the way of browser extensions that I am aware of. Here the only way is to keep the tab character in the clipboard by having previously copied it from some other program like notepad.

javascript solutions require the name of the textbox where they will act on, so this is far from ideal or practical. While alt keycode combinations under both browsers still execute the normal tab character keypress event so they don't work either.

A Dwarf

Posted 2009-11-09T14:32:17.857

Reputation: 17 756

0

or using ahk to insert 4*space in editor:

^Right::
tabspace:="    "
send,%tabspace%    
return 

you can see code details explaintation in ahk code

Lu Zhao

Posted 2009-11-09T14:32:17.857

Reputation: 1

0

To type the tab key in a text box, you can use a script like this (text box which accepts tab keys is named txtLongText):

[VB.NET]

txtLongText.Attributes.Add("onkeydown", _
"if(event.which || event.keyCode){if ((event.which == 9)" & _ 
"|| (event.keyCode == 9)) {document.getElementById('" & _ 
txtLongText.ClientID + "').selection = " & _
document.selection.createRange();" & _ 
txtLongText.ClientID & ".selection.text = " & _
" String.fromCharCode(9);return false;}} else {return true}; ")

[C#]

txtLongText.Attributes.Add("onkeydown", 
"if(event.which || event.keyCode){if ((event.which == 9)" +
"|| (event.keyCode == 9)) {document.getElementById('"+
txtLongText.ClientID + "').selection = document.selection.createRange();" + 
txtLongText.ClientID + ".selection.text = String.fromCharCode(9);return false;}} else {return true}; ");

Or better, to avoid hard coding, you can put this code in a function named EnableTabType. The function has only one parameter, which specifies what is TextBox control where you need to enable typing of Tab characters.

[VB.NET]

Public Sub EnableTabType(tb As TextBox)
    tb.Attributes.Add("onkeydown", _
    "if(event.which || event.keyCode){if((event.which == 9)" & _ 
    "|| (event.keyCode == 9)) {document.getElementById('" & _ 
    tb.ClientID & "').selection=document.selection.createRange();" & _
    tb.ClientID & ".selection.text = " & _
    " String.fromCharCode(9);return false;}}else{return true};")
End Sub 

[C#]

public void EnableTabType(TextBox tb)
{ 
    tb.Attributes.Add("onkeydown", 
    "if(event.which || event.keyCode){if ((event.which == 9)" +
    "|| (event.keyCode == 9)) {document.getElementById('"+
    tb.ClientID + "').selection = document.selection.createRange();" +
    tb.ClientID + ".selection.text = String.fromCharCode(9);return false;}} else {return true}; ");
}

Source: http://www.beansoftware.com/ASP.NET-Tutorials/Access-Tab-Key.aspx

admintech

Posted 2009-11-09T14:32:17.857

Reputation: 6 970

0

Tab Grabber is kinda like Tabinta, only for Chrome (allows TABs in textarea fields).

SiteKickr

Posted 2009-11-09T14:32:17.857

Reputation: 801

0

Use jQuerry's tabby! Supports select row and press tab odr SHIFT TAB

http://www.herby.sk/trapped/bower_components/jquery-tabby/textarea.mirror.html

liquid2026

Posted 2009-11-09T14:32:17.857

Reputation: 1