1. Home
  2. Computing & Technology
  3. JavaScript

Toggle Action Cookie Script

2. Obtain the Script

clr gif
Join the Discussion

Questions? Comments?

More of this Feature

Introduction

To add the ability to toggle between two actions to your web page you first need to copy the Javascript code into the head section of your page.

Copy the above Javascript and save it to an external file. I called mine toggle.js.

We can now link the Javascript into the head of our web page using the following code:

<script type="text/javascript" src="toggle.js"></script>

The final step is to replace the alert('welcome'); and alert('hello');statements with whatever processing it is that you want to have performed on alternate visits to the page.

Introduction and Sample | Obtain the Script
Explore JavaScript
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

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

  1. Home
  2. Computing & Technology
  3. JavaScript

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

All rights reserved.