[CSS/IE] incompatibilté de couleurs.

Bonjour,

Je souhaiterais que l utilisateur puisse changer la couleur de ma page web. Le code marche bien sous Mozilla, mais ne fonctionne, bien sur pas, sous IE.
Seule la couleur du texte a changé. (l'arriere plan et les bordures sont restés intacts).

Quelqu un saurait-il ma dire ce qui cloche?

Merci,

function changeColorTheme(selectedColor) {

  
  var colorvar=selectedColor;

  var regles=new Array();
  if (document.styleSheets[0].cssRules) regles=document.styleSheets[0].cssRules;
  else if (document.styleSheets[0].rules) regles = document.styleSheets[0].rules;
 
  setCookie('cookiecolor',colorvar,30);
  
 	regles[8].style.color = colorvar;
 	regles[9].style.backgroundColor = colorvar;
  	regles[10].style.backgroundColor =colorvar;
  	regles[12].style.borderColor = colorvar;
   	regles[24].style.color = colorvar;
	regles[29].style.borderColor = colorvar;
	regles[33].style.borderColor =colorvar;
	regles[39].style.backgroundColor = colorvar;	
	regles[42].style.color = colorvar;
	regles[44].style.color = colorvar;
	regles[45].style.color = colorvar;
 	
} 
Configuration: Windows Vista
Firefox 2.0.0.6

2 réponses

  1. Merci pour la réponse, mais j utilise une feuille de style.

    'regle[8]', par exemple, correspond à la 9eme regle de ma feuille de style.

    En fait, cette ligne de code marche bien.( la couleur du texte change)
    regles[8].style.color = colorvar;

    mais pas celle ci:
    regles[9].style.backgroundColor = colorvar;
    1. Bonjour,

      Vas sur : http://www.editeurjavascript.com
      ou directement : http://www.editeurjavascript.com/scripts/search.php?asked=changer+couleur+fond&dest=1

      En voici un qui fonctionne sur IE 7.0.
      Récupéré sur une page, peut être qu'il n'est pas complet.
      Pas testé sur une autre config.

      <!-- DEBUT DU SCRIPT -->
      <SCRIPT LANGUAGE="JavaScript">
      /*
      SCRIPT EDITE SUR L'EDITEUR JAVASCRIPT
      http://www.editeurjavascript.com
      */
      Col = new Array;
      Colf = new Array;
      Col[0] = "white";
      Colf[0] = "Blanc";
      Col[1] = "green";
      Colf[1] = "Vert foncé";
      Col[2] = "seagreen";
      Colf[2] = "Vert";
      Col[3] = "red";
      Colf[3] = "Rouge";
      Col[4] = "purple";
      Colf[4] = "Violet";
      Col[5] = "magenta";
      Colf[5] = "Violet clair";
      Col[6] = "fusia";
      Colf[6] = "Rose foncé";
      Col[7] = "pink";
      Colf[7] = "Rose";
      Col[8] = "navy";
      Colf[8] = "Bleu marine";
      Col[9] = "blue";
      Colf[9] = "Bleu";
      Col[10] = "skyblue";
      Colf[10] = "Bleu ciel";
      Col[11] = "cyan";
      Colf[11] = "Bleu clair";
      Col[12] = "coral";
      Colf[12] = "Corail";
      Col[13] = "teal";
      Colf[13] = "Turqoise";
      Col[14] = "tan";
      Colf[14] = "Ocre";
      Col[15] = "orange";
      Colf[15] = "Orange";
      Col[16] = "gold";
      Colf[16] = "Or";
      Col[17] = "yellow";
      Colf[17] = "Jaune";
      Col[18] = "cream";
      Colf[18] = "Vert clair";
      Col[19] = "gray";
      Colf[19] = "Gris";
      Col[20] = "lightgrey";
      Colf[20] = "Gris clair";
      Col[21] = "brown";
      Colf[21] = "Marron";
      Col[22] = "black";
      Colf[22] = "Noir";
      </SCRIPT>
      <!-- FIN DU SCRIPT -->
      <!-- DEBUT DU SCRIPT -->
      <!--
      SCRIPT EDITE SUR L'EDITEUR JAVASCRIPT
      http://www.editeurjavascript.com
      -->
      <FORM NAME=ChoixCouleur>
      <SELECT NAME="couleur" onChange="document.bgColor = ChoixCouleur.couleur.options[ChoixCouleur.couleur.selectedIndex].value">
      <SCRIPT LANGUAGE="JavaScript">
      a = 0;
      while (a!=23)
      {
      document.write('<OPTION VALUE="' + Col[a] + '">' + Colf[a] + '\n');
      a++
      }
      </SCRIPT>
      </SELECT>
      </FORM>
      <!-- FIN DU SCRIPT -->