Piotrek W said:
How to write some text into current document at text coursor position?
You could use some ranges, see below (tested IE5.5 and Mozilla 1.3).
The example uses document.onclick for simplicity, but you could also
use some more advanced triggers (storing the mouse position for IE in
a mousemove handler, and grabbing the rangeParent/rangeOffset from the
mousemove evt object for Gecko).
document.onclick = function(evt){
var d=document;
if(d.selection && d.body && d.body.createTextRange){ //IE
var no_tags="inputtextarea";
if(d.selection.type=="Text" &&
no_tags.indexOf(event.srcElement.nodeName.toLowerCase())==-1){
var rng=d.body.createTextRange();
rng.moveToPoint(event.x, event.y);
rng.pasteHTML("Foo");
}
}else if(window.getSelection){ //Gecko
var sel=ng=window.getSelection(), rng;
if(sel.rangeCount){
rng=sel.getRangeAt(0);
if(rng.startContainer.nodeType==Node.TEXT_NODE){
var txt=d.createTextNode("Foo"),
txtAfter=rng.startContainer.splitText(rng.startOffset);
txtAfter.parentNode.insertBefore(txt, txtAfter);
sel.removeAllRanges();
}
}
}
}
HTH
Yep.