Ver Mensaje Individual
  #6 (permalink)  
Antiguo 01/05/2007, 15:56
Asyolath
 
Fecha de Ingreso: abril-2006
Mensajes: 80
Antigüedad: 18 años, 1 mes
Puntos: 2
Re: Insertar foco entre dos elementos

El primer código que te he pasado tenía el defecto de que en IE no colocaba el foco donde tocaba, he modificado la función para que ahora sí que lo haga. Funciona en IE y en Firefox. Si tampoco te sirve pues ya no sé exactamente qué es lo que quieres... pruébalo a ver

Código:
function tamfuente(abierto, cerrado) {
 var txtarea = document.perfil.firma;
 var navegador= navigator.appName;
 txtarea.focus()
 if (navegador=='Microsoft Internet Explorer') {
  seleccion = document.selection.createRange();
  seleccion.text = abierto + seleccion.text + cerrado;
  fin= seleccion.text.length;
  inicio= -(fin+cerrado.length);
  seleccion.text= etiqueta+seleccion.text+cierre;
  seleccion.move('character', inicio); 
  seleccion.moveEnd("character", fin);
  seleccion.select();
  return;
 }
 else
 {
  var textoEntero= txtarea.value;
  var pos1= txtarea.selectionStart;
  var pos2= txtarea.selectionEnd;
  var pos3= textoEntero.length;
  var textoAnterior= textoEntero.substring(0,pos1)+abierto;
  var textoSeleccionado= textoEntero.substring(pos1,pos2);
  var textoPosterior= cerrado+textoEntero.substring(pos2,pos3);
  txtarea.value= textoAnterior+textoSeleccionado+textoPosterior;
  txtarea.selectionStart= pos1+abierto.length;
  txtarea.selectionEnd= pos2+abierto.length;
  return;
 }
 almacenado(txtarea);
}