Hey guys. I really need your help on this one: i need a script, which will rotate around 5 images, and the images will rotate only when the visitor presses refresh. can anyone help me? thanks! Roy.
Use the following code. Call the function rotateImg on the load event of the page function rotateImg(){ var arImg = new Array(5); arImg[0] = 'images/1.gif'; arImg[1] = 'images/2.gif'; arImg[2] = 'images/3.gif'; arImg[3] = 'images/4.gif'; arImg[4] = 'images/5.gif'; var idx = getCookie('img_idx'); idx = idx ? idx : 0; img = document.getElementById('image_id').src = arImg[idx++ % 5]; setCookie('img_idx', idx); } function getCookie(name){ var start = document.cookie.indexOf( name + "=" ); var len = start + name.length + 1; if((!start) && (name != document.cookie.substring(0, name.length))) return null; if(start == -1) return null; var end = document.cookie.indexOf( ";", len ); if(end == -1) end = document.cookie.length; return unescape(document.cookie.substring(len, end)); } function setCookie(name, value, expires, path, domain, secure){ var today = new Date(); today.setTime(today.getTime()); if(expires)expires = expires * 1000 * 60 * 60 * 24; var expires_date = new Date(today.getTime() + (expires)); document.cookie = name+"="+escape( value ) + ((expires) ? ";expires="+expires_date.toGMTString() : "" ) + ((path) ? ";path=" + path : "" ) + ((domain) ? ";domain=" + domain : "" ) + ((secure) ? ";secure" : "" ); } Code (markup):