JavaScript

  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

JavaScript

  1. Home
  2. Computing & Technology
  3. JavaScript

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

All rights reserved.