A cookie is a variable that is stored in a visitor's computer. This cookie is sent whenever the same computer requests a page through the browser. You can use JavaScript to create and retrieve a cookie's value.
below to see To delete all cookie value code
function ClearCookie () {
var keys=document.cookie.match (/[^ =;] + (? = =)/g);
if (keys) {
for (var i = keys.length; i--;)
document.cookie=keys[i]+ ' =0;expires= ' + new Date (0). toUTCString ()
}
}
Examples of cookies:
Name Cookie
When a visitor visits the page for the first time, he or she may fill in his or her name. The name is stored in the cookie. When visitors visit the site again, they receive a welcome word like "Welcome John doe!". And the name is retrieved from the cookie.
Password cookie
When a visitor accesses the page for the first time, he or she may fill in his or her password. Passwords can also be stored in cookies. When they visit the site again, the password is retrieved from the cookie.
Date Cookie
When a visitor visits your site for the first time, the current date can be stored in a cookie. When they visit the site again, they receive a message similar to: "Your last visit is on Tuesday August 11, 2005!". The date is also retrieved from the cookie. Creating and storing cookies
In this example we want to create a cookie that stores the visitor's name. When visitors visit the site for the first time, they are asked to fill in their names. The name is stored in the cookie. When visitors visit the site again, they receive a welcome word.
First, we'll create a function that stores the visitor's name in the cookie variable:
function Setcookie (c_name,value,expiredays)
{
var exdate=new date ()
Exdate.setdate (Exdate.getdate () +expiredays)
document.cookie=c_name+ "=" +escape (value) +
((expiredays==null)? "": "Expires=" +exdate.togmtstring ())
}
The parameters in the above function hold the name, value, and expiration days of the cookie.
In the above function, we first convert the number of days to a valid date, and then we save the cookie name, value, and its expiration date to the Document.cookie object.