want to insert text at cursor position in rechtextbox

May 4, 2008 at 10:36 AM
in my web application i am inserting text in RichText box at particular cursor position by using document.selection and then using createRange(). it works fine in IE but in Mozilla document.selection is not working. and hence i am not able to insert text in textarea at particular cursor position in Mozilla.


May 5, 2008 at 3:09 PM
Not sure but the problem is probably because the two different browsers use different methods to modify the text... ... ... Probably will need to write something that checks to see if the various objects are available for usage, if document.selection & document.selection.createRange are available then use them, if window.getSelection is available then use it.

if (document.selection && document.selection.createRange) {
//do createRange code here
}
else if (window.getSelection) {
//do getSelection / getRangeAt code here
}
May 5, 2008 at 3:31 PM
actually i am doing the same thing
code is as below

alert(richeditor.GetWindow().getSelection().getRangeAt(0).startOffset);


this is returning me current cursor position.
but here the problem is, current cursor position is representing cursor position in current selected line.
say if RichtextBox contains 3 lines
each line contains 10 characters and suppose my cursor is at 5th position in 2nd line
the above code returns current cursor position as 5
but i want it as 15 as it is actually at 15th position.




mrfinger wrote:
Not sure but the problem is probably because the two different browsers use different methods to modify the text... ... ... Probably will need to write something that checks to see if the various objects are available for usage, if document.selection & document.selection.createRange are available then use them, if window.getSelection is available then use it.

if (document.selection && document.selection.createRange) {
//do createRange code here
}
else if (window.getSelection) {
//do getSelection / getRangeAt code here
}