PDA

View Full Version : How to show a javascript filled layer only once per session using a cookie



Frituurman
01-31-2008, 12:58 PM
Hello,

I'm using a flying helicopter script on my site (http://www.deltaisis.nl), but I want the darn thing to show only once per session. since I'm a complete n00b.. what do I do to get this done? I've tried numerous things, but I kept getting errors.. All the code is easy accesseble (just look at the source)

Please help!

Kind regards,

Frituurman

jscheuer1
01-31-2008, 02:11 PM
<script type="text/javascript">
//De variabele is hier helicopter. Komt in dit script terug. Variabele wordt overal gebruikt.
var helicopter
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}
function pagestart(){
//Hier kun je de dimensies van de afbeelding invullen. Indien de helicopter 100px breed is en 50px hoog, vul dan de onderstaande maten in (hoogte - 13 / breedte - 12):
if(!readCookie('heli')){
helicopter=new Chip("helicopter",87,38);
movechip("helicopter");
createCookie('heli',1);
}
}
if (window.addEventListener)
window.addEventListener("load", pagestart, false)
else if (window.attachEvent)
window.attachEvent("onload", pagestart)
else if (document.getElementById)
window.onload=pagestart
</script>