Cookies
along the way of JavaScript

The World Wide Web is both the gateway to a marvelous universe and a gaping portal for invasion. So our browsers are understandabely paranoid about our invited guests' access to our storage media. 'Cookies' are the exception to the rule. They allow visiting web pages to save and retrieve information in your computer. You can capture the process and refuse the information or let it happen sight unseen. There are limits on cookies - no more than 300 cookies, no cookie larger than 4K, no more than 20 cookies per domain.

What are these snippets for? They allow a web page to deposit a piece of information that persists until its defined expiration date. The only required information is the name and its value. [Cookies without dates last only until the end of the session]. So a visitor can leave a date, and thereby know when you revisit a site. Or a commercial site can use nondated cookies for its 'shopping basket'. Or you can store persistent variables between sessions. etc.

The JavaScript cookie guru is Bill Dortch, who wrote the JavaScript Functions we've all used to manage cookies. The Oxherder's version in the source code are adaptations of his code:

setCookie(name, value, [expiration date], [secure]):
The setCookie function requires only the first two arguments [three if it is to persist]. They are the name of the cookie; the value of the cookie; the expiration date [in days from today]; and 'true' if a secure channel is required.
getCookie(name)
The getCookie function returns the specified cookie's value [or null if it doesn't exist].
deleteCookie(name)
The deleteCookie function deletes the specified cookie by setting its expiration date to the current date.
The Cookie Functions [myCookie]

There turn out to be more uses for cookies than you might imagine. JavaScript tends to lose variables when you do a lot of window popping or refreshing. Storing info in local cookies solves the problem. If you leave a date as a cookie when people visit your site, you can use it to mark things as 'new' based on the date of their last visit. It's a nice way to password a registered visitor without their having to remember the password.

netpad is an example of using cookies to save snippets of information from a web page [remember - only 4K per cookie]. Type in some text and save it. Close netPad - then reopen it. Leave this webpage altogether. Come back [within 7 days], and your text will still be there.