BIT 116 – Scripting

Cookies


Part 1: Simple (session-only) cookie usage

Put a textbox and a couple buttons onto a web page.  The page should ask the user to input a score, and when the user clicks on one of the buttons, the page should store that score into a cookie.  Another button should allow you to clear the score out of the textbox, and a third button should allow you to retrieve that score (and display it into the textbox, again).

Part 2: More permanent cookie usage

Using your previous example, try saving a score, clearing the box, and then retrieving that score.  Then try exiting the browser, and starting up a new browser window, and then try to retrieve the previous score (Before storing any scores in this second window).  Notice how the cookie you created in the first session (window) no longer exists.

Building off that previous example, add an expiration date to your cookie, so that you can keep scores around even if the user exits the browser window.

Part 3: Multiple Cookies

Building on the previous examples, see if you can store two key/value pairs into the same cookie.  The key points are that you'll still need to name the cookie like normal (ie, the string will start with cookieName=...), each subkey/value pair will need to be separated by somethign ( : works well - avoid = and ; )and that you'll have to pick some character (maybe the & symbol) to separate the subkey/value pairs.  Once you've got this working correctly, make sure that you can set the expiration date on the entire cookie, so that you can store, for example, the 'high scores' that people have gotten on your game in the browser.