/    Sign up×
Community /Pin to ProfileBookmark

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*60*1000));
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

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Sterling_IsfineJan 07.2010 — [CODE]

///// createCookie("counter", current_visit, 365);

if(current_visit === 4){
..............

current_visit = 0;
}

createCookie("counter", current_visit, 365);[/CODE]
Copy linkTweet thisAlerts:
@Ryan_RowlettauthorJan 08.2010 — Perfect! Thank you thank you.
×

Success!

Help @Ryan_Rowlett spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...