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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
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.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Administering MySQL Databases on the Web Using PHP · Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
So what is an Oracle Nested Table? · E-Discovery Architectures 101 · eBay Embraces Big Sellers, Cyber Monday Trends