Bueno, no he probado tu código pero creo que tu problema es el que tuve yo hace poco... El IExplore no detecta la selección del campo. Pues yo encontré por ahí este código (el parámetro "editor" en mi caso es un TEXTAREA), una vez ejecutado ya se les ha asignadao valor a selectionStar y selectionEnd y se puede ejecutar tu código anterior como si fuera mozilla, que ahora si reconocerá estas propiedades:
Código:
function AveriguaRangoIE(editor)
{
if (document.selection)
{ // Esta mierda es necesaria para averiguar
//las posiciones de inicio y fin de seleccion en IExplore
// We'll use this as a 'dummy'
var range = document.selection.createRange();
if ((range != null) && (range.htmlText.length > 0))
{ //Si habia seleccion => range.htmlText.length > 0
var stored_range = range.duplicate(); // Select all text
stored_range.moveToElementText( editor ); // Now move 'dummy' end point to end point of original range
stored_range.setEndPoint( 'EndToEnd', range ); // Now we can calculate start and end points
editor.selectionStart = stored_range.text.length - range.text.length;
editor.selectionEnd = editor.selectionStart + range.text.length;
alert('Comienzo ' + editor.selectionStart);
alert('Fin ' + editor.selectionEnd);
}
else
{
alert('No hay rango');
//js_getCursorPosition(editor);
}
return;
}
}
Mi problema es cuando no hay ningún texto seleccionado, con el IExplore no soy capaz de averiguar la posicion del cursor y de volver a colocarlo después en el mismo sitio, he visto por ahí funciones para hacerlo pero son muy complicadas y no consigo adaptarlas a mi editor...
¿Tu sabes como hacerlo?
Por cierto, he dejado los alert en el código, puedes quitarlos cuando lo tengas probado..