spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / cookies 123456

JavaScript Cookies:

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Making the Most from the Drudgery of Others

Now 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.)
Examples will spawn a new window.

1. Basic Example - Original Doc JavaScript Column is Here:
(http://www.webreference.com/js/column8/)

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.
Click here for demo

2. Using A Counter - Original Doc JavaScript Column is Here
(http://webreference.com/js/column8/counter.html)

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.
Click here for demo and code

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.
Click here for demo and code

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.
Click here for demo and code

To Continue, Use The Arrow Buttons 123456

http://www.internet.com

Comments are welcome
Produced by Greg Meckes

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Created: Jan. 12, 2000
Revised: Jan. 14, 2000

URL: http://webreference.com/programming/javascript/cookies/page5.html