home -- outline -- lectures -- assignments -- discussion -- tips -- links --



Using Cookies with Javascript

First put the following code in the head of your file:
<script src="http://www.classes.cs.uchicago.edu/classes/current/CS101/html/cookies.js">
</script>

You will then have two functions you can use for cookies.

  • setCookie(name,value) creates a cookie of the given name and value. This cookie will expire after the current session ends.
  • setCookie(name,value,days) same but will expire after so many days.
  • getCookie(name) will return the value of the cookie with the given name. Will return null if cookie has expired or never been created.
Here is an example using Cookies

For more advanced information see the Netscape Javascript Guide.