JavaScript and Cookies : Cookie : Development JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Development » Cookie »

 

JavaScript and Cookies




















A cookie is a small bit of information stored in a text file on the user's computer by a browser.

The cookie object is part of the Document object.

Cookies can be created, set, and modified by setting the appropriate values of the cookie property.

A cookie has four name attributes: expires, path, domain, and secure.

By default, a cookie lasts only during the current browsing session.

For a cookie to last beyond the current browsing session, the expires attribute must be set.

The value of expires attribute can be set to any valid date string.

The path attribute specifies the domain associated with the cookie.

The level of association begins at the specified path and goes down into any subfolders.

So for example, suppose http://www.navioo.com/examples/cookie.html was setting a cookie and wanted the cookie to be shared across Web pages on the navioo.com domain.

To do this, the cookie path attribute needs to be set to "/".

This allows the cookie to be accessed from any page on the www.navioo.com Web server.

If the path was set to "/examples", the cookie would only be valid to pages in the examples folder and its subfolders.

If the secure attribute is specified, the cookie will be only be transmitted over a secure channel (HTTPS).

If secure is not specified, the cookie can be transmitted over any communications channel.





HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Development
» Cookie