Regresar   Foros del Web > Programación para sitios web > Javascript

El registro es Gratis en Foros del Web
Respuesta
 
Herramientas Buscar en Tema Desplegado
Antiguo 26/03/08, 18:04:08   #1 (permalink)
DragonX tiene un muy buen nivel de karmaDragonX tiene un muy buen nivel de karma
 
Registrado: nov 2002
Ubicación: Funkyland
Mensajes: 6.507
DragonX is offline  
Intercambiar hojas de estilo

Amigos realmente hice todo lo que estaba a mi alcance, pero no logro lo que quiero, a ver si me pueden dar una mano.

Estaba buscando la forma de poder armar una botonera para que el usuario pudiera cambiar el estilo del site, y buscando me encontré con este artículo "Haciendo funcionar a las hojas de estilos alternativas" y después de leerlo, hacer mil errores y volverlos a correjir me dí cuenta que tenía un enlace al script directo, seguí el enlace y caí en Alistapart y allí encontré el script, el cual copio a continuación:

Código HTML:
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
Seguí todos los pasos, linkie este js a mi HTML

Código HTML:
<script src="js/script_gral.js" type="text/javascript"></script>
Y acomodé mis hojas de estilo:
Código HTML:
<link href="css/original.css" rel="stylesheet" type="text/css" title="Estilo Original" />
<link href="css/turquesa.css" rel="alternate stylesheet" type="text/css" title="Estilo Turquesa" />
En mi HTML coloqué los links, como decía el artículo

Código HTML:
<a href="#" onclick="setActiveStyleSheet('Estilo Original'); return false;">original</a>
<a href="#" onclick="setActiveStyleSheet('Estilo Turquesa'); return false;">turquesa</a>
y para mi sorpresa...AHÍ ESTABA FUNCIONANDO sin problemas, obviamente la index, ahora cuando pasaba a otra sección esta pasaba a su estado original, lo cuál me parecía lo más lógico.

Ahora mi pregunta es ¿existe alguna manera de hacer que la hoja de estilo seleccionada por el usuario lo acompañe en toda la navegación? y de ser posible, con este código puedo hacer algo?

Desde ya mil gracias
un abrazo
  Responder Con Cita
Antiguo 26/03/08, 19:33:48   #2 (permalink)
DragonX tiene un muy buen nivel de karmaDragonX tiene un muy buen nivel de karma
 
Registrado: nov 2002
Ubicación: Funkyland
Mensajes: 6.507
DragonX is offline  
Re: Intercambiar hojas de estilo

jejejeej ya salió, andaba en todas lo que pasa es que no había puesto las hojas de estilo
  Responder Con Cita
Respuesta


Califica este Tema - Intercambiar hojas de estilo.

Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado Califica este Tema
Califica este Tema:

Reglas del foro
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está activado
Las caritas están activado
Código [IMG] está activado
Código HTML está desactivado


Todas las horas son GMT -6. La hora es 14:58:33.

Message Board Statistics

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95