PDA

View Full Version : popup once per browser session cookie not working


AshleyQuick
01-27-2003, 04:14 PM
Here's what I have:


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function showRemote() {
self.name = "main";

var windowprops = "toolbar=0,location=0,directories=0,status=0, " +
"menubar=0,scrollbars=0,resizable=0,width=500,height=575";

OpenWindow = window.open("popup_FebruaryWebPromo.html", "remote", windowprops);
}

showRemote()

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function loadornot(){
if (get_cookie('poppedup')==''){
showRemote()
document.cookie="poppedup=yes"
}
}

loadornot()

// End -->
</script>

A1ien51
01-27-2003, 04:57 PM
Are you using this online, or on your computer??
It memory serves me right, it will not work on your computer.

AshleyQuick
01-27-2003, 05:42 PM
I'm developing on one computer, and looking on another. Besides, this cookie script "should" (or is supposed to be) per browser session. Either way, it's not working on the other computer.

Can someone troubleshoot?

ConfusedOfLife
01-27-2003, 06:15 PM
Your proggie isn't working coz it shouldn't work!
Here are my 2 cents:

[list=1]
Go and read about the cookies, because if you want them to stay in the clients computer, you have to define the expiresvalue for each cookie and giving it a future date in GMT. So, the general syntax would look like this:

document.cookie = "newCookie=myVal; expires=a date in GMT"

after doing this, then you could be sure that the cookie stays in the clients computer till the time expires or you delete it yourself ( by reseting the expires date)
Getting the cookies in this way ( using the indexOf function ) is a real torture! I would have recommend the split function. You could use it in this way:

myCookies = document.cookie.split("; "); // Note the space that I added after the semicolon in the split function, it SHOULD be there and you SHOULD put that space when you want to register a new cookie ( See the previous code, you see a space between the ; and the expires property
cookieJar = new Array();
for ( i=0; i<myCookies.length; i++)
{
cookieJar[i] = new Array();
cookieJar[i]["name"] = myCookies[i].split("=")[0];
cookieJar[i]["value"] = myCookies[i].split("=")[1];
}

[/list=1]

king443
01-27-2003, 10:14 PM
First - AshleyQuick needs a "once per browser session". So we should not use the expires= tag. What is done is correct.

Second - I saw a call to showRemote() right in the script - in addition to the call inside the loadornot fuction. So every time you refresh the page, the showRemote() will get called. Removing that call will fix it.

Hope it helps.

ConfusedOfLife
01-28-2003, 10:24 PM
Maybe I'm wrong, but I think she wants to have that pop up page for any computer that didn't visit her page b4, right? So, to do this, we have to use the expires tag, that the next time that the same computer wants to view the page, we recognize it and do not show the pop up.
And for calling the ShowRemote() function outside of loadornot(), you're right. I didn't see that!

AshleyQuick
01-29-2003, 03:36 PM
Removing showRemote() worked, thanks.

Ash