This file sets/ retrieves a cookie, “counter” and passes the value (=page visits)to Flash using flashvars. I want the cookie to delete on visit number 4 and then reset itself on the following visit, 5. For background, the cookie value dictates which of 4 possible frames a visitor will see; so, visit 1 = frame 1 etc. So on visit 5, I want to display frame 1 again (since there is no frame 5).
Here is the whole script. I am placing a note near the problem area below. Thanks to anyone who looks at this.
<script>
function createCookie(name,value,days) {
var expires = “”;
if(days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60
expires = “; expires=”+date.toGMTString();
}
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;
}
var counter = readCookie(“counter”);
var prior_visits = (counter !== null) ? parseInt(counter, 10) : 0;
var current_visit = prior_visits +1;
createCookie(“counter”, current_visit, 365);
if(current_visit === 4){
alert(“Clear Cookie”); <!–I want to replace this alert with a bit of script which will clear the cookie. A side note; will expiring the cookie cause conflicts with resetting on subsequent visits?–>
}
var flashvars = {
visits: current_visit
};
swfobject.embedSWF(“main_banner.swf”, “myContent”, “189”, “151”, “9.0.0”, false, flashvars);
</script>
Thanks again, Ryan