1328 Part V (Yahoo web hosting) . Putting JavaScript to Work
Saturday, January 5th, 20081328 Part V . Putting JavaScript to Work while (i < cLen) { var j = i + labelLen if (mycookie.substring(i,j) == label) { var cEnd = mycookie.indexOf( ; ,j) if (cEnd == -1) { cEnd = mycookie.length } return unescape(mycookie.substring(j,cEnd)) } i++ } return } A global variable is used to act as a speedy intermediary between the actual browser cookie and the functions here that need to access cookie data. The setCurrState() function contains a construction that you don t see much in this book, but is quite valid. Notice the three-piece assignment statement. Evaluation of this statement works from right to left. The rightmost expression concatenates a cookie label and the value passed in as a parameter to the function. Note, too, that the value is passed through the escape() function to properly URL-encode the data for the sake of data integrity (so that spaces and odd punctuation don t mess up the mechanism). The concatenated value is assigned to the document.cookie property. With the value safely dropped into the cookie (it may be just one of several name/value pairs for this domain), the value of the document.cookie property (which includes all name/value pairs for the domain) is assigned to the mycookie global variable. Retrieving information from the cookie still requires a bit of parsing to be on the safe side. If other cookie writing were to come from the current server path, more than one cookie would be available to the current document. Parsing the entire cookie for just the portion that corresponds to the currState labeled cookie ensures that the script gets only the data previously saved to that label. In an earlier version of this code, the frequent access to the document.cookie property inside the while loop of getCurrState() wasn t a problem until the sluggish cookie reading performance of NN4 got in the way. Adapting the code to use the global variable for the repetitive parsing of the cookie value rescued the day. The focal point The toggle() function, which is pivotal in this outline scheme, receives as a parameter the index number of the db array element whose content the user just clicked. The purpose of this function is to grab a copy of the current outline state from the cookie, alter the binary representation of the clicked item, and feed the revised binary number back to the cookie (where it governs the display of the outline after the document reloads): // **function that updates persistent storage of state** // toggles an outline mother entry, storing new value in the cookie function toggle(n) { var newString = var currState = getCurrState()
You want to have a cheap webhost for your apache application, then check apache web hosting services.