Jump to content


Photo

Template Alternativo


  • Faça o login para participar
1 reply to this topic

#1 kpuano

kpuano

    Turista

  • Usuários
  • 26 posts
  • Sexo:Não informado
  • Localidade:Campinas - SP - Brasil

Posted 28/09/2004, 21:32

Oi,

Estou fazendo um blog que tem como escolher o template sabe? Em CSS, que você clica no link e muda o CSS da pagina, mudando as cores, imagens e etc...

Então, eu coloquei esse código na head:

<link href="css.css" rel="stylesheet" title="azul">
<link href="css2.css" rel="alternate stylesheet" title="laranja">

e esse no body:

<a href="#" onclick="setActiveStyleSheet('laranja');">Laranja</a><br>
<a href="#" onclick="setActiveStyleSheet('azul');">Azul</a>

E quando eu clico, não muda nada na página, e era para mudar a cor dos links e a imagem do topo.

Clique aqui para ver: http://fabiokp.cienc...blog/index.html

O que está errado?

Obrigado
Blog: http://www.fabiocaps...r.terra.com.br/
E-mail: fabiocapsouza@hotmail.com
ICQ: 250739394

#2 danillonunes

danillonunes

    Se tudo está funcionando bem, algo está errado, e vice-versa

  • Usuários
  • 182 posts
  • Sexo:Não informado
  • Localidade:Campinas - SP

Posted 29/09/2004, 00:18

Ta faltando o script para a troca do layout. Você colocou no link setActiveStyleSheet, mas não colocou o que faz essa função.

Para funcionar, coloque esse código:
//funcao de troca dinamica de layout
//retirado do site tableless.com.br

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);

num javascript externo ou interno.

Para colocar num javascript externo, cole o código no bloco de notas e salve em um arquivo .js. Depois você chama ele na página com
<script type="text/javascript" src="http://seusite.com/arquivo.js"></script>

Para colocar internamente, ou seja, dentro do arquivo html, é só colocar o código entre as tags <script language="javascript"> e </script>
Abraços
Marcus Danillo
http://danillonunes.net




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq