spacer
Yehuda Shiran January 9, 2002
Differentiating between Cookies
Tips: January 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
ActiveState Debuts Open Source Business Suite
Salesforce Offers Visual App Builder
Codesion Steps Out From CVS's Shadow

One way to store and retrieve data on the client side is by using cookies. The cookie property is a member of the document object. You can store thousands of cookies per client. You can distinguish between cookies by several parameters:

  • name. The name of the cookie. A quoted string. Required. Example: "listSelectedIndex".
  • value. The value of the cookie. A numeric value or a quoted string. Required. Example: 5.
  • expires. Expiration date of the cookie. A date object. Optional. Defaults to the end of the current session. Example: now.
  • path. The path for which the cookie is valid. A quoted string. Optional. Example: "/foo/bar/html". Defaults to the path of the document or script that set the cookie.
  • domain. The domain for which the cookie is valid. A quoted string. Optional. Example: "www.internet.com". The default value of the domain attribute is the host name of the server that set the cookie.
  • secure. A Boolean value indicating whether the cookie transmission requires a secure protocol. Default to false.

To set up a date object to expire in one year, you need to multiply the following:

  • 365 days in a year.
  • 24 hours in a day.
  • 60 minutes in an hour.
  • 60 seconds in a minute.
  • 1000 milliseconds in a second.

The following line of code computes the date object for the year-long cookie:

  var now = new Date();
  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Use Web Caching to Make Your Web Site Faster · Creating an Online Shopping Cart Mechanism in PHP · Log JavaScript Errors Using an AJAX-driven Web Service
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Configuring Granular Settings for a Database Level Audit · The Perils of a Web 2.0 Transition on Your Business Processes · Facebook Redesigns Site —Again — Nears 400M Mark