![]() Buy Now |
How do we let visitors chose a background color and have that color displayed when they return? This example is copyrighted by Curious Cat Creations. We grant you the right to use it so long as you retain our copyright notice and link in your code. We would also appreciate a link on your page but none is required. |
![]() |
- Read more on cookies or JavaScript.
- Set your background color for Curious Cat Code.
Cut and paste code:
<HTML> <HEAD>
<script><!--
// Stored Background Choice by Curious Cat Creations: www.curiouscat.com/design/
// Explanation of how to add this to your site: www.curiouscat.com/cookies/example.cfm
// This code is copyrighted by Curious Cat Creations
// We grant you the right to use it if you include this entire notice (links appreciated
// but not required). Provided AS-IS with no warranty.
// Cookie Functions - Second Helping (21-Jan-96)
// Written by: Bill Dortch, hIdaho Design - bdortch@netw.com
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr)); }function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break; }
return null; }function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : ""); }
// --></SCRIPT>
</HEAD><script>
<!--
background = GetCookie('background')
if (background == "r") { document.bgColor="red"; }
else if (background =="o") { document.bgColor="orange"; }
else if (background =="g") { document.bgColor="green"; }
else if (background =="b") { document.bgColor="blue"; }
else if (background =="p") { document.bgColor="purple"; }
else if (background =="w") { document.bgColor="white"; }
else if (background =="y") { document.bgColor="yellow"; }
else { document.bgColor = "white"; }
// -->
</script>
<P>
<P> </FORM>Insert your html here
<input type="button" Value="Orange" onClick=" {
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 31 * 9));
SetCookie('background','o', expdate);
document.bgColor='orange';
return false; } " >
<input type="button" Value="Blue" onClick=" {
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 31 * 9));
SetCookie('background','b', expdate);
document.bgColor='blue';
return false; } " >
<input type="button" Value="White" onClick=" {
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 31 * 9));
SetCookie('background','w', expdate);
document.bgColor='white';
return false; } " >
<input type="button" Value="Yellow" onClick=" {
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 31 * 9));
SetCookie('background','y', expdate);
document.bgColor='yellow';
return false; } " > <P> </body> </html>Insert your html here

