Cookies in JavaScript


Download Some Cool Website Software Now !
This site designed with Coffee Cup HTML Editor ++ ver. 6.2

HTML Tutorial

JavaScript Examples
Rollovers
MouseDown
JS Clock
CountDown
Status Window
Status Window 2
Random Image
JS Cookies
Background Changer
Scrolling Banner
Members Area

Special Effects using JavaScript

Use Cookies for customized greetings

Enter your Name:

Note the greeting above and the form. Enter your name and click "Register".

A cookie is a piece of information placed on your system that can be used to identify you from previous visits. Though they are somewhat controversial, for the most part cookies really are harmless. With this cookie, all it does is identify you by name only if you input your name. If you don't you won't get the cookie. This particular cookie expires after 1 year from the date of your last visit. If at any time for the year you come back to this site you will automatically get the "customized, personalized" greeting.

*NOTE: If this appears not to work for you, then you have "Cookies Disabled"
in your Browser's preferences.

How it works: This is a 3 part script.

The first part of the script resides between the <HEAD> and the </HEAD> tags. It first sets the cooky's values. For example, it gets today's date in case you hit "Register" and get the cookie, and it checks to see if this cookie already exists on your system. If so it gets the cookie, updates it with the new date and resets the expiration date for another year.

The second part is within the "BODY" of the web page, if Part 1 of the script has found a previous visit cookie on your system then the web page displays the personalized "Welcome Back, Your Name" greeting. If no cookie exists it displays the generic "Welcome to Cookies in JavaScript" greeting.

The third part that makes it work is the "<FORM>". Part 1 has already set the cookie's value so should you fill out the form with your name, you get the cookie and the personalized greeting for one year. Don't fill out the form and the script does absolutely nothing. You get no cookie.

It is possible to get cookies without filling out the form. But I wouldn't do that to you on my site.

The script looks like this:

Recommended Books
Ceate Your First Web Page: In A Weekend Building Better Web Pages Advanced HTML Companion HTML Web Magic Javascript CD Cookbook Core Web Programming

Top of Page?



Download Some Cool Website Software Now !