JavaScript Cookies Example

This page contains a JavaScript that stores information about the last time a reader visited the page

Please note that JavaScript is currently only available in Netscape Navigator 2.0 or higher.
Do not assume that all in your audience are using a JavaScript enabled browser.

These JavaScripts use Persistent Client State HTTP Cookies to store information about the last time a reader visited the page. A cookie is a mechanism that allows information to be stored across multiple sessions.

In this example two cookies are stored containing information about last date and number of times the reader has visited a page (containing these cookies). Since the cookies are stored on the readers hard disk you - the author - will not be able to extract information about the reader.

Cookies can also be used for many other purposes, such as keeping readers preferences for viewing a site, storing passwords, implementing a shopping cart for online business or for keeping track of access rights for a specific reader viewing pages created on the fly on the server.

Here is an example:

Hello, !

Reload this page to see the text above updated.

How to use:
Rename the constants 'my_LastVisit' and 'my_NumVisits' to something unique for the current page (maybe use some part ot the url) or else it won't work correctly if other uses this script! These constants are located at the beginning of the HEAD section in this file. It is important to do this!

You may want to change the text inside function GetLastVisit() to something more appropriate for your site.

Finally use this code inside the BODY section to display the information in the browser:

<SCRIPT>document.write (GetLastVisit())</SCRIPT>