[turboid] javascript solutions

Home     Contact     Search     About me
Other
06 Jun 2012

Text Cursor Management with JavaScript

Take control over the text cursor!

Finally, you can let your script paste any text copied by the user, move the text cursor in input fields to any position you whish, remove selection marks or restore them.

If you were looking a long time for ways of text cursor handling in JavaScript, probably your search has come to an end. Turboid provides you with several functions you can control the text cursor with. Some of them are explicitly for input fields ans text area elements, other are appliable on the rest of the document.

The following is a reference which lists the functions belonging to the Turboid text cursor management. In order to use the extra functions, simply download the free Turboid framework and put it into the directory of your HTML file, then write this line into the head section of your HTML file, and that's it:

	

Cursor.paste(str1 [,str2] )

Pastes a string at the current text cursor position. The argument 'str2' is optional, that means Cursor.paste(str) is sufficient. It is for the case if a whole part of the text is marked, then it pastes 'str1' at the beginning of the selection mark and 'str2' at the end of it.


Cursor.getPos(["start"|"end"|0|1])

Gets the current text cursor position. All arguments are optional, that means Cursor.getPos() is sufficient. If the text cursor is a whole selection mark it is recommended to use Cursor.getPos("start") and Cursor.getPos("end") to get the beginning and the end of the selection mark. It works also with Cursor.getPos(0) and Cursor.getPos(1). - Attention: This function is for input fields and text areas only. If no such element is currently focussed, the function returns 'null'.


Cursor.to(pos [,pos2])

Sets the text cursor at the desired position. The second argument is optional, that means Cursor.to(pos) is sufficient. If the second argument is set, this function causes a marking effect. - Attention: This function is for input fields and text areas only. If no such element is currently focussed, the function returns 'null'.


Cursor.toEnd()

Sets the text cursor to the end.


Cursor.unselect()

Removes text selection marks, no matter if the selected text is in an input field or a text area element or elsewhere in the document.


Cursor.save()

Saves the current text selection mark (not the text). - Attention: This is not for input fields or text area elements, but only the other parts of the document.


Cursor.restore()

Restores a text selection mark saved with Cursor.save() if it became lost through a click elsewhere in the document. - Attention: This is not for input fields or text area elements, but only the other parts of the document.


Comments

Anonym wrote on 2016-09-25 at 18:51:59 h:

I'd like to test the apostrophes.

Anonym wrote on 2016-09-25 at 18:53:36 h:

I'd like to test the apostrophes.

Anonym wrote on 2016-09-25 at 18:54:15 h:

I'd like to test the apostrophes.

Anonym wrote on 2016-09-25 at 18:57:45 h:

I'd like to test the apostrophes.

Anonym wrote on 2016-09-25 at 18:58:34 h:

I'd like to test the apostrophes.

Anonym wrote on 2016-09-25 at 18:59:16 h:

I'd like to test the apostrophes.

Add comment:

Name: (required)
E-Mail: (required, remains invisible)
Website:
Comment:
Please check all (anti-spam):