html - What is the purpose of this JavaScript code? -
i poking around inspect element , came across this:
numberofdivstorandomdisplay = 10; var cookiename = 'divramdomvaluecookie'; function displayrandomdiv() { var r = math.ceil(math.random() * numberofdivstorandomdisplay); if (numberofdivstorandomdisplay > 1) { var ck = 0; var cookiebegin = document.cookie.indexof(cookiename + "="); if (cookiebegin > -1) { cookiebegin += 1 + cookiename.length; cookieend = document.cookie.indexof(";", cookiebegin); if (cookieend < cookiebegin) { cookieend = document.cookie.length; } ck = parseint(document.cookie.substring(cookiebegin, cookieend)); } while (r == ck) { r = math.ceil(math.random() * numberofdivstorandomdisplay); } document.cookie = cookiename + "=" + r; } (var = 1; <= numberofdivstorandomdisplay; i++) { document.getelementbyid("randomdiv" + i).style.display = "none"; } document.getelementbyid("randomdiv" + r).style.display = "block"; } displayrandomdiv();
what purpose? curious, :)
this code assumes have div
's id's "randomdiv1", "randomdiv2" etc.
it reads cookie named divramdomvaluecookie
. if it's present, contains integer value id of div shown ("randomdiv" + value of cookie).
then, hide divs, , show 1 of divs, different div id stored in cookie. if cookie not present, display random div.
this script has hard-coded number of div's in numberofdivstorandomdisplay
variable.
Comments
Post a Comment