HighDots Forums  

Once Per Session Cookie

Javascript JavaScript language (comp.lang.javascript)


Discuss Once Per Session Cookie in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Yonih
 
Posts: n/a

Default Once Per Session Cookie - 06-03-2008 , 09:29 AM






Hey Yall,

I am trying to incorporate a Once Per session Cookie that will expire
once the browser is closed so some one who comes to my website will
see my popup the first time her visits the website but it wont keep
showing as one navigates throughout the site however if he closes the
browser and reopens out site it will show again. Here is the script
that I was using that started out to work once per session but after
publishing the site it went to once per machine (until I cleared my
cookies)
Please let me know how to change it or what code I can use.


//This calls onlyOnce Code
onLoad="onlyOnce()

<script type="text/javascript">
// initpopup is my Popup Script
function initpopup() {
window.open(initpopup())
}
</script>

<script type="text/javascript">
// the new code
function onlyOnce() {
if (document.cookie.indexOf("hasSeen=true") == -1) {
var later = new Date();
later.setFullYear(later.getFullYear()+10);
document.cookie =
"hasSeen=true;expires="+later.toGMTString();
// call the old function
initpopup();
}
}
</script>

Please let me know if you know a way to change this to a once per
session script or if you have a new one to use.
Thanks

Yoni

Reply With Quote
  #2  
Old   
Bart Van der Donck
 
Posts: n/a

Default Re: Once Per Session Cookie - 06-03-2008 , 10:03 AM






Yonih wrote:

Quote:
I am trying to incorporate a Once Per session Cookie that will expire
once the browser is closed so some one who comes to my website will
see my popup the first time her visits the website but it wont keep
showing as one navigates throughout the site however if he closes the
browser and reopens out site it will show again. Here is the script
that I was using that started out to work once per session but after
publishing the site it went to once per machine (until I cleared my
cookies)
Please let me know how to change it or what code I can use.

//This calls onlyOnce Code
onLoad="onlyOnce()

* <script type="text/javascript"
// initpopup is my Popup Script
* * function initpopup() {
* * * window.open(initpopup())
* * }
* </script

* <script type="text/javascript"
* * // the new code
* * function onlyOnce() {
* * * if (document.cookie.indexOf("hasSeen=true") == -1) {
* * * * var later = new Date();
* * * * later.setFullYear(later.getFullYear()+10);
* * * * document.cookie =
"hasSeen=true;expires="+later.toGMTString();
* * * * // call the old function
* * * * initpopup();
* * * }
* * }
* </script

Please let me know if you know a way to change this to a once per
session script or if you have a new one to use.
The cookie remains present when 'expires' is set to a valid time value
in the future. If you omit it, the cookie becomes non-persistent and
is deleted when the browser session ends. So...

document.cookie = 'hasSeen=true;path=/;';

...should solve your problem.

Info:
http://en.wikipedia.org/wiki/HTTP_cookie#Expiration

Hope this helps,

--
Bart


Reply With Quote
  #3  
Old   
Yonih
 
Posts: n/a

Default Re: Once Per Session Cookie - 06-03-2008 , 10:18 AM



Bart,

Thank you so much. That seems to be working in IE however not in
Firefox. I am going to try and publish it on my site to see if it
works better there. I will post my results. Either Way Thank you again
so much

Yoni Hirsch

Reply With Quote
  #4  
Old   
Bart Van der Donck
 
Posts: n/a

Default Re: Once Per Session Cookie - 06-03-2008 , 10:34 AM



Yonih wrote:

Quote:
Thank you so much. That seems to be working in IE however not in
Firefox. I am going to try and publish it on my site to see if it
works better there. I will post my results. Either Way Thank you again
so much
You're welcome. I suggest to make sure the cookies of the domain are
empty before testing (in FireFox, or with any other browser) and of
course restarting the browser. Additionally, the path might be
ommitted/adapted too, depending on which files or directories should
obtain access to the cookie.

--
Bart


Reply With Quote
  #5  
Old   
Yonih
 
Posts: n/a

Default Re: Once Per Session Cookie - 06-03-2008 , 12:49 PM



Bart,

Thank you so much everything seems to be working in IE and Firefox.
Your awesome.

Yoni

Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.