Free web host - 1338 Part V . Putting JavaScript to Work
Thursday, January 10th, 20081338 Part V . Putting JavaScript to Work if (document.styleSheets) { isCSS = true isNN4 = false } else { isCSS = false isNN4 = true } To each of the cookie storage functions from the original version, I add a branch to handle the storage and retrieval of state data for CSS browsers, simply setting and getting the global variable. This may seem to be more indirect than is necessary, but it is essential to allow the reuse of many functions in other parts of the code so that those areas don t have to worry about browser platform. Notice that the label for this outline s cookie is slightly different from that of the earlier version. This difference allows you to open both outliners with NN4 in the same session and not worry about one cookie value overlapping with the other. // ** functions that get and set persistent data ** // set persistent data function setCurrState(setting) { if (isNN4) { NN4Cookie = document.cookie = currState2= + escape(setting) } else { // for CSS, data is saved as a global variable instead of cookie CSScurrState = setting } } // retrieve persistent data function getCurrState() { if (isCSS) { // for CSS, data is in global var instead of cookie return CSScurrState } var label = currState2= var labelLen = label.length var cLen = NN4Cookie.length var i = 0 while (i < cLen) { var j = i + labelLen if (NN4Cookie.substring(i,j) == label) { var cEnd = NN4Cookie.indexOf( ; ,j) if (cEnd == -1) { cEnd = NN4Cookie.length } return unescape(NN4Cookie.substring(j,cEnd)) } i++ } return } The toggle() function is called by the onClick event handler of the links surrounding the widget icon art in the outline. A variable number of parameters are passed to this function, so that the parameters are extracted and analyzed via the arguments property of the function. Both browsers with only a few small
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.