Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-27-2003, 04:14 PM   PM User | #1
AshleyQuick
Regular Coder

 
Join Date: Jun 2002
Location: USA
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
AshleyQuick is an unknown quantity at this point
popup once per browser session cookie not working

Here's what I have:

Code:
<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>
AshleyQuick is offline   Reply With Quote
Old 01-27-2003, 04:57 PM   PM User | #2
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
Are you using this online, or on your computer??
It memory serves me right, it will not work on your computer.
A1ien51 is offline   Reply With Quote
Old 01-27-2003, 05:42 PM   PM User | #3
AshleyQuick
Regular Coder

 
Join Date: Jun 2002
Location: USA
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
AshleyQuick is an unknown quantity at this point
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?
AshleyQuick is offline   Reply With Quote
Old 01-27-2003, 06:15 PM   PM User | #4
ConfusedOfLife
Regular Coder

 
Join Date: Jul 2002
Location: Iran
Posts: 695
Thanks: 0
Thanked 0 Times in 0 Posts
ConfusedOfLife is an unknown quantity at this point
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:
Code:
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:
Code:
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]
ConfusedOfLife is offline   Reply With Quote
Old 01-27-2003, 10:14 PM   PM User | #5
king443
New Coder

 
Join Date: Jan 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
king443 is an unknown quantity at this point
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.
king443 is offline   Reply With Quote
Old 01-28-2003, 10:24 PM   PM User | #6
ConfusedOfLife
Regular Coder

 
Join Date: Jul 2002
Location: Iran
Posts: 695
Thanks: 0
Thanked 0 Times in 0 Posts
ConfusedOfLife is an unknown quantity at this point
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!
ConfusedOfLife is offline   Reply With Quote
Old 01-29-2003, 03:36 PM   PM User | #7
AshleyQuick
Regular Coder

 
Join Date: Jun 2002
Location: USA
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
AshleyQuick is an unknown quantity at this point
Removing showRemote() worked, thanks.

Ash
AshleyQuick is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:09 AM.


Advertisement
Log in to turn off these ads.