Following code i modified to make it work in the firefox browser. whats going wrong. pls suugest the workarounds
but its not working in firefox
if (document.selection)
{
var objRange = document.selection.createRange();
var sOldRange = objRange.text;
//set this string to a small string that will not normally be encountered
var sWeirdString = '#%~';
//insert the weirdstring where the cursor is at
objRange.text = sOldRange + sWeirdString; objRange.moveStart('character', (0 - sOldRange.length - sWeirdString.length));
//save off the new string with the weirdstring in it
var sNewText = textElement.value;
//set the actual text value back to how it was
objRange.text = sOldRange;
//look through the new string we saved off and find the location of
//the weirdstring that was inserted and return that value
for (i = 0; i <= sNewText.length; i++) {
var sTemp = sNewText.substring(i, i + sWeirdString.length);
if (sTemp == sWeirdString) {
var cursorPos = (i - sOldRange.length);
return cursorPos;
}
} }
else if (window.getSelection)
{
/* var objRange = document.getSelection.createRange();
var sOldRange = objRange.text;
//set this string to a small string that will not normally be encountered
var sWeirdString = '#%~';
//insert the weirdstring where the cursor is at
objRange.text = sOldRange + sWeirdString; objRange.moveStart('character', (0 - sOldRange.length - sWeirdString.length));
//save off the new string with the weirdstring in it
var sNewText = textElement.value;
//set the actual text value back to how it was
objRange.text = sOldRange;
//look through the new string we saved off and find the location of
//the weirdstring that was inserted and return that value
for (i = 0; i <= sNewText.length; i++) {
var sTemp = sNewText.substring(i, i + sWeirdString.length);
if (sTemp == sWeirdString) {
var cursorPos = (i - sOldRange.length);
return cursorPos;
}
}*/
}
}