Ver Mensaje Individual
  #5 (permalink)  
Antiguo 31/05/2006, 02:03
zaqpz
 
Fecha de Ingreso: agosto-2005
Ubicación: Argentina, Capital Federal
Mensajes: 435
Antigüedad: 18 años, 8 meses
Puntos: 2
Bueno probando y probando llegué a algo. Acá te dejo una función para traer estilos mediante AJAX multi-navegador. Usé el addRule que me enteré por ahí de su existencia en un sitio de Microsoft para hacer que todo funcione en IE y la creación de un nodo de texto que luego lo asigno al style para todos los demás navegadores.

TraeStyle.php
Código:
<html>
<head>
<script type="text/javascript">
if(navigator.userAgent.indexOf("MSIE")>=0) navegador=0; // IE
else navegador=1; // Demas

// Crear la clase AJAX con el nombre nuevoAjax

function traeStyle()
{
	ajax=nuevoAjax();
	ajax.open("POST", "TraeStyle2.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("trae=1");
	
	ajax.onreadystatechange=function() 
	{
		if (ajax.readyState==4)
		{ 
			var nuevoStyle=document.createElement("style");
			document.getElementsByTagName('head')[0].appendChild(nuevoStyle);
			
			if(navegador==0)
			{
				var textoFormateado=ajax.responseText;
				textoFormateado=textoFormateado.split("{");
				
				var ultimaEtiqueta=document.styleSheets[document.styleSheets.length-1];
				ultimaEtiqueta.addRule(textoFormateado[0], "{"+textoFormateado[1]);
			}
			else
			{
				var texto=document.createTextNode(ajax.responseText);
				nuevoStyle.appendChild(texto);
			}
		} 	
	}
}
</script>
</head>

<body>
<a href="javascript:traeStyle();">Trae style</a>
<br>
<a href="#" onClick="document.getElementById('texto').className='clase'">Ver style</a>
<br>
<p id="texto">Texto</p>
</body>
</html>
TraeStyle2.php
Código:
<?php
if($_POST["trae"]==1)
{
	echo "
	.clase
	{
		color:#FF0000;
	}";
}
?>
Espero te resulte útil.
Saludos.
__________________
R4DS en español | R4DS en inglés

Última edición por zaqpz; 31/05/2006 a las 02:08