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.
 
 
<HTML> 
     <HEAD> 
       <SCRIPT language="Javascript"> 
     // <!-- hide from other browsers 

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

     function getCookie(name)  { 
             var start=0; 
             var end=0; 
             cookieyes=false; 
             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; 
                     break; 
             } i++ 

     } 
             if (cookieyes==true){ 
             start = end + 1; 
             end= document.cookie.indexOf(";",start); 
             if (end < start) 
                     end=document.cookie.length; 
             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 
           getCookie("favcolorc"); 
             col = val; 
             if (val == "red" ) { document.location="ccok.red.html"} 
             if (val == "blue" ) { document.location="cook.blue.html"} 
             if (val == "green" ) { document.location="cook.green.html"} 
     } 
//--> 
</SCRIPT> 

</HEAD> 

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