Cookies are a way of storing information about a user on the users computer. Cookies can be used to track a users visits to and path through a web site, store a users choices, and much more.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site
   WARNING!
What you learn from these Totally FREE
Einstein Newsletters could cause your friends to mistake you for someone else!
  [] automobiles
  [] business
  [] parenting
  [] computers
  [] contests
  [] education
  [] entertainment
  [] food/wine
  [] free stuff
  [] genealogy
  [] health/fitness
  [] home/garden
  [] humor
  [] marketing
  [] investing
  [] pets
  [] inspiration
  [] self-improve
  [] recreation
  [] travel
  [] womens stuff
  [] writing/reading
Click here and choose as many as you like!

Cookie Power Made Easy

Cookies are a way of storing information about a user on the users computer. Cookies can be used to track a users visits to and path through a web site, store a users choices, and much more. A cookie can not be larger than 4096 bytes, only a maximum of 20 cookies can be stored per domain, and only 300 cookies total can be stored.

Where cookies are stored on the users computer varies with the browser version and the operating system. In some cases all cookies are written to a single file. On Windows 2000 cookies are stored under each users My Documents folder. On Windows 98 cookies are stored under the Windows folder.

All the cookies saved from an individual web page are stored in one file. Each web page has a related cookie file. When a user requests a web page from a server, the browser searches for a related cookie file on the users computer. The cookie file would have been created by previous visits to that web page.

If any cookies are found they are loaded into the page's document.cookie property. If you are familiar with the browser document object model, you would expect the cookie property to contain a collection of cookies. Instead, the cookie property contains a single string of text.

It is easy to store a cookie from your web page. Just use JavaScript to assign values to the document.cookie property as shown below.

document.cookie="cookiename=cookievalue";

The line above shows the minimum requirement to create a cookie. A cookie may contain up to five parts separated by semicolons as shown below.

"name=value; expires=date; path=path; domain=domain; secure"

Because all the cookies related to one web page or one domain are written to a single file, retrieving a cookie is a bit more difficult. For experimenting or debugging you can generate a popup dialog box displaying a list of all the cookies related to a web page by typing the following line into the address text box of your browser.

JavaScript:alert(document.cookie.split(';').join('\n')

To use cookies with your web page you have to be able to extract the specific cookie that you are interested in from the browsers cookie property string. The JavaScript code below will perform that function.

function getCookie(name)
{
 var cookieFound = false;
 var start = 0;
 var end = 0;
 var cookieString = document.cookie;
 var i = 0;

 while(i <= cookieString.length)
 {
  start = i;
  end = start + name.length;
  if(cookieString.substring(start,end) == name)
  {
    cookieFound = true;
    break;
  }
  i++;
 }

 if(cookieFound)
 {
  start = end + 1;
  end = document.cookie.indexOf(";",start);
  if(end < start)
    end = document.cookie.length;
  return document.cookie.substring(start,end);
 }
 return "";
}

frequently we want to store more than a single piece of information for a web page. You could achieve this by setting and retrieving multiple cookies. However, if you have other cookie setting code on your web site, for example advertising banners, you could quickly exceed the 20 cookies per domain maximum. When you exceed the maximum, the browser will delete the oldest cookie and retain the most recent 20.

Web Design Sections
Java Script Quick Reference
Java Script Data Types
Java Script Reserved Words
Java Script Arithmetic Operators
Comparison Operators
Java Script Arrays
Java Script Character Encoding and Decoding
The if/else Structure
The switch/case Structure
The for Loop
The while Loop
The break Statement
The continue Statement
JavaScript Math Object
Round a Number
Determine Absolute Value
Determine Minimum and Maximum
Generating Random Numbers
Java Script Trigonometric Methods
Java Script Number Object
Format a Number as Currency
Java Script Strings
Compare Two Strings
Find a Character or a Substring Within a String
Include a Quote Character in a String
Include a Backslash Character in a String
Define Lines in a String
Use Escape to Replace Dangerous Characters
Convert a Number to a String
Convert a String to a Number
The Document Object Model (DOM)
Accessing Web Page Elements
Interactively Set Webpage Colors
Get Webpage File Date and File Size
Dueling Windows
Cookie Power Made Easy

[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2007 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269