JavaScript Class

Home Help Table of Contents Class Stuff

Cookies!

Cookies are small computer-generated text files (no larger than 4K) that you receive when you stop into certain sites. Unless you have made a point of setting your browser's preferences so you do not accept cookies, you probably have a cookie sitting in your browser's directory right now. The use of cookies is quite widespread.

The cookie is a property of the document object. This property is a string that returns a report detailing all visible and un-expired cookies that are associated with the specified document. The value returned using this method only contains the name and value attributes of the associated cookies in a single string.

When setting the cookie property, the following syntax must be used:

"name" = "value"; expires = "date"; path = "directory"; domain = "domainName"; secure

The "date" parameter must be in the format as returned by the toGMTString() method of the Date object. The expires attribute is optional; not setting this will mean that the cookie will expire when the user shuts down their browser. If set, the cookie survives until the set expiry date. "domainName" sets the cookie's visibility to a particular domain although this attribute is rarely used as it defaults to the domain of the carrying document and visibility of the cookie is normally restricted to this document alone. The path parameter is similar to domain in that it restricts the cookie's visibilty to the specified directory on the web server. The secure attribute is less commonly used. It is a Boolean (true or false) that, when true, suggests that the browser should only make secure (SSL) URL requests when the cookie is sent to the server.

Example and useage...





Home Help Table of Contents Class Stuff