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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Going Native With Chrome
Mozilla Fixes Firefox Flaws as 3.5 Release Nears
Microsoft and Novell Still Bosom Buddies

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 >
XML and PHP Simplified · Creating a ASP.NET Contact Form · Data Filtering with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Intel to Host Live Nehalem Q&A · 12 Tips to Troubleshoot Network File-Sharing · 10 Tips for Selling on Kijiji