Hey, wanna use cookies in your Javascript?! It's as easy as 1-2-3. Actually it's easier.

1. Grab the following code that was so nicely written by Bill Dortch of hIdaho Design. Note this is Javascript code, not HTML!!! So download via the shift-click method or whatnot.

2. Place the following two lines in your HTML document to use cookies:

 <script language="JavaScript" src="cookies.js">
3. That's it... You can now use cookies... You should look through the code to see how all the functions work.. It's pretty self explanitory. However, here is the example you can find at the end of the code:
var expdate = new Date ();
FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now 
SetCookie ("ccpath", "", expdate);
SetCookie ("ccname", "hIdaho Design ColorCenter", expdate);
SetCookie ("tempvar", "This is a temporary cookie.");
SetCookie ("ubiquitous", "This cookie will work anywhere in this domain",null,"/");
SetCookie ("paranoid", "This cookie requires secure communications",expdate,"/",null,true);
SetCookie ("goner", "This cookie must die!");
document.write (document.cookie + "<br>");
DeleteCookie ("goner");
document.write (document.cookie + "<br>");
document.write ("ccpath = " + GetCookie("ccpath") + "<br>");
document.write ("ccname = " + GetCookie("ccname") + "<br>");
document.write ("tempvar = " + GetCookie("tempvar") + "<br>");

Return to the Front Page