Thursday, April 17, 2008

How to Use Cookies in JavaScript?

Cookies are bits of information that a browser stores in your visitor's computer. They are helpful in that they allow you to store things like your visitor's preference when they visit your site or other types of data specific to a particular user. This session deals with how you can use JavaScript to create, store, recover and delete cookies.

What Kinds of Data Can Be Stored in a Cookie?

A cookie is essentially a string of text characters not longer than 4 KB. Cookies are set in name=value pairs, separated by semi-colons. For instance, a cookie might be a string like the following:

"theme=blue; max-age=60; path=/; domain=thedomain.com"
This example cookie has 4 variable/value pairs:

max-age, which is set to 60,
path, which is set to the slash character "/",
domain, which is set to "thedomain.com",
and theme, which is set to "blue".

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home