Hallo,
ich habe ein Problem mit Cookies. Ich möchte, dass man mit Hilfe von Buttons die Hintergrundfarbe und Textfarbe ändern kann (Buttons sind nicht dabei, da ich das mit dem Wechselschema schon hinbekommen habe). Doch ich möchte den Besuchern meiner Homepage das Leben nicht allzu schwer machen und diese Textfarbe und Hintergrundfarbe jeweils in Cookies speichern, doch irgendetwas mache ich falsch... nur was? Würde mich über eure Hilfe freuen! :D
MFG
Fleischi
Hier ist der Quelltext:
<html>
<head>
<script type="text/javascript">
function selectcolor()
{
if(document.cookie)
farbe = document cookie;
document.body.style.background = 'farbe';
else
farbe = prompt("Welche Hintergrundfarbe möchtest du haben?\n" +
"rot, grün, blau, gelb, schwarz oder weiß", "weiß").toLowerCase();
switch(farbe)
{
case "rot":
document.body.style.background = 'red none;';
break;
case "grün":
document.body.style.background = 'green none;';
break;
case "blau":
document.body.style.background = 'blue none;';
break;
case "gelb":
document.body.style.background = 'yellow none;';
break;
case "schwarz":
document.body.style.background = 'black none;';
break;
default:
document.body.style.background = 'white none;';
break;
}
document.cookie = farbe;
}
</script>
<script type="text/javascript">
function selecttextcolor()
{
farbe = prompt("Welche Textfarbe möchtest du haben?\n" +
"rot, grün, blau, gelb, schwarz oder weiß", "weiß").toLowerCase();
switch(farbe)
{
case "rot":
linkfarbe = "red";
document.body.style.color = 'red';
break;
case "grün":
linkfarbe = "green";
document.body.style.color = 'green';
break;
case "blau":
linkfarbe = "blue";
document.body.style.color = 'blue';
break;
case "gelb":
linkfarbe = "yellow";
document.body.style.color = 'yellow';
break;
case "schwarz":
linkfarbe = "black";
document.body.style.color = 'black';
break;
case "weiß":
linkfarbe = "white";
document.body.style.color = 'white';
break;
default:
linkfarbe = "white";
document.body.style.color = 'white';
break;
}
var links = document.getElementsByTagName('a')
for(i=0; i < links.length; i++)
{
links[i].setAttribute("style", "color: "+linkfarbe+";", 1);
}
}
</script>
</head>
<body>
</body>
</html>