| home / programming / javascript / cookies |
|
|
Making the Most from the Drudgery of OthersNow that we know what they are and how they work, let's insert them into an HTML document. You can write your own cookie scripts, but why not use some ready-to-eat cookie scripts created by the Pros themselves? They're usually free and you can modify them for your own use. We'll use Doc JavaScript's cookie scripts, and make some simple modifications. You can also find some good examples and code at JavaScriptSource.com. We'll also explore how to combine different scripts to make your own cookie recipes! Cookie Examples - Seeing them in action(Make sure that your browser is set to accept cookies for
this section.) 1. Basic Example - Original Doc JavaScript Column is Here: Let's look at a basic example at a cookie in action. This example simply
uses a JavaScript prompt that asks the user for input - in this case it's
a name. The name is then stored in the cookie file on the user's computer.
When the user returns, the name is there giving them a personalized message. 2. Using A Counter - Original Doc JavaScript
Column is Here This example keeps track of how many visits a user has made to a given URL. When
the user returns, the number increases by 1. 3. Combining 2 Scripts Now let's combine the first 2 cookie scripts to create a personal greeting.
Here we will modify and combine the 2 scripts. 4. Getting creative with 3 scripts This time we get creative. We'll combine the first 2 script examples, then
add a third. The catch here is that instead of displaying the visits using
the "document.write" method, we'll give the user the option of clicking on
a link to launch a pop up window to display the visit number. I used the Doc
JavaScript
handy dandy interactive form to "construct a script segment that
launches a window with specified features". This one is fun to experiment
with. |
| To Continue, Use The Arrow Buttons |
|
Comments are
welcome
Produced by Greg Meckes
Created: Jan. 12, 2000
Revised: Jan. 14, 2000
URL: http://webreference.com/programming/javascript/cookies/page5.html