<pre class= "javascript" name= "code" >
var fm = document.getelementsbytagname (' form ') [0];
var button = document.getelementsbyname ("button");
Gets the value of a cookie function GetCookie (index) {var allcookies = Document.cookie; var cookie_pos = allcookies.indexof (index), if (cookie_pos! =-1) {Cookie_pos + = index.length + 1;var cookie_end = Allcookie S.indexof (";", Cookie_pos); if (cookie_end = =-1) { cookie_end = allcookies.length; } var value = unescape (allcookies.substring (Cookie_pos, cookie_end)); } return value; Gets the cursor position in the text function getcursortposition (ctrl) {var Caretpos = 0;//IE supportif (document.selection) {ctrl.focus (); var Sel = Document.selection.createRange (); Sel.movestart (' character ',-ctrl.value.length); Caretpos = Sel.text.length;} else if (Ctrl.selectionstart | | ctrl.selectionstart = = ' 0 ') Caretpos = Ctrl.selectionstart;return (Caretpos);}
Gets the position of the text cursor and sets a cookie to store the position of the cursor at any point in the variable var textpos = 0;textcontent.onclick = function () {Textpos = Getcursortposition (textcontent);d ocument.cookie= "textpos=" +textpos;textpos = GetCookie ("Textpos");} Write function of the string content (string) {s = textcontent.value;fm.content.value = s.substring (0,getcookie ("Textpos") ) +string+s.substring (GetCookie ("Textpos"));}
<pre class= "php" name= "code" >//click the button to add content to the cursor at the text field in the form Button[0].onclick = function () {content (' [b][/b] ');}