HTML Tutorial |
JavaScript Examples |
Rollovers |
MouseDown |
JS Clock |
CountDown |
Status Window |
Status Window 2 |
Random Image |
JS Cookies |
Background Changer |
Scrolling Banner |
Members Area |
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: