JavaScript and Cookies : Cookie « Development « JavaScript Tutorial

Home
JavaScript Tutorial
1.Language Basics
2.Operators
3.Statement
4.Development
5.Number Data Type
6.String
7.Function
8.Global
9.Math
10.Form
11.Array
12.Date
13.Dialogs
14.Document
15.Event
16.Location
17.Navigator
18.Screen
19.Window
20.History
21.HTML Tags
22.Style
23.DOM Node
24.Drag Drop
25.Object Oriented
26.Regular Expressions
27.XML
28.GUI Components
29.Dojo toolkit
30.jQuery
31.Animation
32.MS JScript
JavaScript Tutorial » Development » Cookie 
4.4.1.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.java2s.com/examples/cookie.html was setting a cookie and wanted the cookie to be shared across Web pages on the java2s.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.java2s.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.

4.4.Cookie
4.4.1.JavaScript and Cookies
4.4.2.Reading Cookies
4.4.3.Writing Cookies
4.4.4.Create a cookie and read it back
4.4.5.Make cookie using Javascript
4.4.6.Delete all cookies
4.4.7.Read cookie value
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.