PDA

View Full Version : need to set cookies to pop up newsletter window


mgrunk
06-08-2008, 11:39 PM
I don't do javascript and have never used cookies on any of my sites - I do some php, anyway, my web customer wants a pop up when someone clicks on the listen button to listen to a show. The pop up would ask them to register. If they click on register, then it shouldn't pop up again, and it shouldn't pop up for another two weeks if they decline.

so my thought is onload -
check to see if showregister cookie exists
if getcookie for showregister is null
get cookie to see if popup was displayed (2 week expire)
if the get cookie returned null
set cookie for popup displayed

<script language= "JavaScript">

function setCookie(cookieName, cookieValue, cookiePath,
cookieExpires)
{

var nowDate = new Date();
nowDate.setDate(nowDate.getDate() + 14);
cookieExpires = nowDate.toGMTString();
document.cookie = cookieName + "=" + cookieValue +
";expires=" + cookieExpires + cookiePath;
}

function getCookie(name)
{
var cookieString = document.cookie;
var index = cookieString.indexOf(name + "=");

if (index == -1)
{
return null;
}

index = cookieString.indexOf("=", index) + 1;
var endstr = cookieString.indexOf(";", index);

if (endstr == -1)
{
endstr = cookieString.length;
}

return unescape(cookieString.substring(index, endstr));
}


function doPopup()
{
var ABoTregister = getCookie('ABoTregister');


if(ABoTregister == '') {
var ABoTpopup = getCookie('ABoTpopup');
if (ABoTpopup == '') {
setCookie('ABoTpopup', 'true', '', '');
// Show the popup window
window.open('http://mydomain/ABoTregister.php', 'ABoTregister', 'toolbar=0, location=0, directories=0, menuBar=0, scrollbars=1, resizable=1, width=300, height=300, left=50, top=50');
}
}
}


</script>
</head>


<body onLoad="doPopup()">


So - it doesn't work - I don't know how to debug - every cookie example gives more info than I need.

And, I assume that when a cookie hits the expiration date it automatically is deleted? I haven't googled that far.

Sorry for the basic question - I've just been all over the place trying to find an answer.

Thanks in advance.

Michelle

Jon Hanlon
06-09-2008, 11:54 PM
http://www.cookiecentral.com