Changes

Understanding JavaScript Cookies

4 bytes removed, 18:09, 15 April 2009
no edit summary
== What is a JavaScript Cookie? ==
Cookies allow you to store information on the computer of the visitor browsing your web site site. Before you get carried away with dreams of secretly moving all those music and image files clogging your hard drive onto the disks of your site visitors you first need to understand some limitations.
Firstly, a cookie can only hold string based name/value pairs (i.e . ''name=value'' settings). You cannot store binary data in a cookie. Secondly, cookies can be a maximum of 4kb in size each. Finally, a single server or domain can only store a total of 20 cookies per user browser.
Another common limitation of cookies is that browsers can be configured to turn off support for cookies. If you design a web site that relies on cookies being supppoted supported by the user's browser there is the possibility that your site will fail to function for a certain percentage of your visitors.
Despite the limitations outlined above, cookies provide an excellent way to maintain state on the clients client's browser. For example, you might want to store information in a cookie so that when a user returns to your site they can pick up where they left off (perhaps partway through completing an all important purchase in an online shopping cart).
== The Structure of a Cookie ==
Cookies are created using the ''cookie'' property of the ''Document'' object. The format of a cookies cookie is as follows:
<pre>