Set the cookie expire date : Cookie « Development « JavaScript DHTML






Set the cookie expire date

 
<html>
<head>
<title>Hello Cookie</title>
<script type = "text/javascript">
var cookName = "cookie1";
var cookVal = "testvalue";
var date = new Date();
date.setTime(date.getTime()+86400000);
var expireDate = date.toGMTString();
var myCookie = cookName + "=" + cookVal + ";expires=" + expireDate;
document.cookie = myCookie;
</script>
</head>
<body>
<p>Hello</p>
</body>
</html>

   
  








Related examples in the same category

1.Reads, writes and deletes current Web page's cookies
2.'cookieEnabled' Example
3.Create a cookie
4.Secure cookie
5.Read all cookies
6.Standard cookie functions: extract Cookie Value
7.Save name to cookie
8.Cookie set, delete, get value and create
9.Cookie utility function
10.Cookie install and delete (remove)
11.Cookie: retrieve a future expiration date in proper format
12.A Cookie Example
13.A Cookie Test Program
14.Quiz Program base on Cookie
15. A Website Access Counter
16. Keeping Track of User Access Time
17.Bill Dortch's Cookie Functions
18.Cookie Preferences
19.Set cookie to document and read it back