1. Home
  2. Computing & Technology
  3. JavaScript
photo of Stephen Chapman
Stephen's JavaScript Blog

By Stephen Chapman, About.com Guide to JavaScript since 2004

Toggle Action

Thursday April 2, 2009
Web pages are usually stateless - meaning that when someone visits a web page the page behaves the same regardless of what they did before.

To allow a web page to behave differently based on what has gone on before you need a way to save information about what has come before. The way to do this is to store a cookie on your visitor's computer that contains information about the past state of the page (or site) and then retrieve that information to determine what to do next. In this example we look at how to get a web page to toggle between two actions based on whether your visitor has come to the page an odd or an even number of times.

Toggle Action
Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.