C
Christina
A project I am working on requires 5 random popup windows that rotate. A
cookie is set each time one of the popups occurs with a 5 day expire period.
The visitor isn't supposed to see the same popup within that 5 day period,
so it needs to rotate to another popup. I have changed it around several
times (setCookie calls randomWin and vice versa) but now have brain burnout.
I'm probably complicating it - a bad habit I have.
My randoms work great, the cookies have landed, but I just can't seem to get
my brain around how to do the rotation. I'm thinking that if the cookie is
found, the array needs to be modified to no longer contain that page, but I
have tried various things incuding splice(), slice(), etc. with no luck.
Guidance? NOTE: the second popup is a popunder.
<script language="JavaScript">
var winArr = new
Array('72hr.htm',630,215,'72hr2.htm',400,150,'72hr3.htm',630,205,'72hr4.htm',570,420,'72hr5.htm',295,260);
var r = randomNumber(winArr.length / 3);
var winUnder = winArr[3];
var winSrc = winArr[r * 3];
var winW = winArr[(r * 3)+1];
var winH = winArr[(r * 3)+2];
function randomNumber(limit){
return Math.floor(Math.random()*limit);
}
function setCookie()
{
var expDate = new Date();
expDate.setDate(expDate.getDate() + 5);
var index = document.cookie.indexOf(winSrc);
if(index == -1)
{
//create cookie
document.cookie=winSrc + "=" + winSrc + ";Expires=" + expDate.toString() +
";";
//display window
randomWin();
}
else
{
//find other window
}
}
function randomWin()
{
if (winSrc != winUnder)
{
window.open(winSrc, "aWindow", "width="+winW+", height="+winH).focus();
}
else
{
window.open(winSrc, "aWindow", "width="+winW+", height="+winH).blur();
}
}
</script>
Thanks,
Christina
cookie is set each time one of the popups occurs with a 5 day expire period.
The visitor isn't supposed to see the same popup within that 5 day period,
so it needs to rotate to another popup. I have changed it around several
times (setCookie calls randomWin and vice versa) but now have brain burnout.
I'm probably complicating it - a bad habit I have.
My randoms work great, the cookies have landed, but I just can't seem to get
my brain around how to do the rotation. I'm thinking that if the cookie is
found, the array needs to be modified to no longer contain that page, but I
have tried various things incuding splice(), slice(), etc. with no luck.
Guidance? NOTE: the second popup is a popunder.
<script language="JavaScript">
var winArr = new
Array('72hr.htm',630,215,'72hr2.htm',400,150,'72hr3.htm',630,205,'72hr4.htm',570,420,'72hr5.htm',295,260);
var r = randomNumber(winArr.length / 3);
var winUnder = winArr[3];
var winSrc = winArr[r * 3];
var winW = winArr[(r * 3)+1];
var winH = winArr[(r * 3)+2];
function randomNumber(limit){
return Math.floor(Math.random()*limit);
}
function setCookie()
{
var expDate = new Date();
expDate.setDate(expDate.getDate() + 5);
var index = document.cookie.indexOf(winSrc);
if(index == -1)
{
//create cookie
document.cookie=winSrc + "=" + winSrc + ";Expires=" + expDate.toString() +
";";
//display window
randomWin();
}
else
{
//find other window
}
}
function randomWin()
{
if (winSrc != winUnder)
{
window.open(winSrc, "aWindow", "width="+winW+", height="+winH).focus();
}
else
{
window.open(winSrc, "aWindow", "width="+winW+", height="+winH).blur();
}
}
</script>
Thanks,
Christina