Download example scripts - 1 Kb
article and hopes to bring its readers to the cruel reality of life by
discussing cookies .
The problem I wanted to solve was "automated" access to
This page has the ability to limit you to one visit per day only (don't forget
to click on the link above!). Until now, each time I first started my browser I
would manually choose a bookmark to
load the page.
Why not create simple script for it?
Because I wanted to have it work under Netscape as well as IE I started to study
Main idea is simple: create a page what will determine whether it has already
been loaded today, and if not make it switch to http://www.thehungersite.com,
and set this page as browser's home page.
Getting the actual page and redirecting is easy. The problem was remembering.
we must use so called cookies. (also see MSDN - Platform SDK/Tools and
Languages/Scripting/JScript/FileSystemObject User's Guide/Working with Files.
There are examples for file access from JScript using ActiveX objects, but of course
this is only good for Microsoft browsers).
Cookies are size-limited variables
associated with a server's domain.
By default cookie expire when the browser closes (not when you leave the page!)
but a script programmer can change this.
Persistent cookies are stored at the users end, separately for every browser user
and separately for every browser (Netscape uses for cookies in file, Internet
Explorer stores every cookie in a separate one). This difference in browsers brings surprises at some servers where you
must log in again and again Be aware that a user can disable cookies in his or
her browser settings.
For a detailed cookie description you can see http://www.netscape.com/newsref/std/cookie_spec.html.
All was fine and nice until time I not tried it with Internet Explorer. Then after
cookieExpires = "01-APR-" + nLyear + " GMT";
document.cookie = cookieName + "=" + cookieValue + "; expires=" + cookieExpires;
and then called
document.cookie was empty.
After experiments and searches in examples I found that
Knowing this, the rest was without problems:
(See attached file: homepage.htm)
If you want use it in your web pages you must minimally test it with different
browsers - and their versions.
Many scripts contain browser type and version checking and lots of if-the-else's
to handle the differences..
You can see source for