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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint