Demonstration of how to use cookies to determine next actions
by Stephen Wilson, Professor, Conceptual Information Arts Program

This page shows how to use cookies to determine what should happen next.  This example assumes you have visited the Wilson.quick.cookie demo page and  selected a favorite color in the demo.  In that demo a cookie called facolorc gets set to the values of red, green, or blue.  The script illustrated below would read the cookie and branch based on that setting.  The branching is accomplished by the "document.location=" javascript function which goes to the url specified after the equal sign. If you have selected a color then you can see the branching in action at cook.branchaction.html.
       <SCRIPT language="Javascript"> 
     // <!-- hide from other browsers 

     // routine to get cookie value ----------- 

     function getCookie(name)  { 
             var start=0; 
             var end=0; 
             var cooktxt= document.cookie; 
             var i=0; 
             templen = name.length 

             while ( i<= cooktxt.length){ 
                     start = i; 
                     end  = start + templen; 
                     if (cooktxt.substring(start,end)==name){ 
                     cookieyes = true; 
             } i++ 

             if (cookieyes==true){ 
             start = end + 1; 
             end= document.cookie.indexOf(";",start); 
             if (end < start) 
             val = document.cookie.substring(start,end); 

     function newload() { 
              // go somewhere based on color 
              // get the cookie favcolorc and branch to pages 
             // (in this example go to red.html, blue.html, or green.html) 
             // this function is called in the BODY tag upon loading 
             col = val; 
             if (val == "red" ) { document.location=""} 
             if (val == "blue" ) { document.location=""} 
             if (val == "green" ) { document.location=""} 


<BODY onLoad= "newload();" > 
This page's only function is to decide what page to load