Sequencial Image

Delete Cookie

When the page is loaded the cookie remembers which array index is next..

For this example, every time the page is loaded the next image in the array is shown.

<script type="text/javascript">
<!--
// Jeff
// www.huntingground.freeserve.co.uk

cookieName="seq_image" 
expDays=365

csiArr=["pic01.jpg","pic02.jpg","pic03.jpg","pic04.jpg","pic05.jpg"]

function showcsImg(){
count = getCookie(cookieName)
if(count==null ||count == csiArr.length ){
count=0
}

document.getElementById("mypic").src=csiArr[count]
count++

exp = new Date()
exp.setTime(exp.getTime() + (expDays*24*60*60*1000))
setCookie(cookieName, count, exp)
}

function setCookie(name, value, expires, path, domain, secure){// An adaptation of Dorcht's function for setting a cookie.
if (!expires){expires = new Date()}
document.cookie = name + "=" + escape(value) + 
((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
((path == null) ? "" : "; path=" + path) +
((domain == null) ? "" : "; domain=" + domain) +
((secure == null) ? "" : "; secure")
}

function getCookie(name){
var arg = name + "="
var alen = arg.length
var clen = document.cookie.length
var i = 0
while (i < clen) {
var j = i + alen
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j)
i = document.cookie.indexOf(" ", i) + 1
if (i == 0) break
}
return null
}

function getCookieVal(offset){
var endstr = document.cookie.indexOf (";", offset)
if (endstr == -1)
endstr = document.cookie.length
return unescape(document.cookie.substring(offset, endstr))
}

function deleteCookie(name,path,domain){ // An adaptation of Dorcht's function for deleting a cookie.
document.cookie = name + "=" +
((path == null) ? "" : "; path=" + path) +
((domain == null) ? "" : "; domain=" + domain) +
"; expires=Thu, 01-Jan-00 00:00:01 GMT"
}

// add onload="showcsImg()" to the opening BODY tag

// -->
</script>

<img id="mypic" src="pic1.jpg">