473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Once Per Session Cookie

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
Jun 27 '08 #1
4 6100
Yonih wrote:
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
Jun 27 '08 #2
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
Jun 27 '08 #3
Yonih wrote:
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
Jun 27 '08 #4
Bart,

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

Yoni
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: chrism | last post by:
Hello, I have a pop-up window that I would like to appear in front of the browser home page when a user opens IE. Problem is, I'd like it to never appear again if the user navigates back to the...
3
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change...
3
by: Enoch Chan | last post by:
I would like to set a Session variable to a value. In Vbscript it should be Session("ZoomValue")=500 How can I set this session variable by using Javascript? Thanks
4
by: Chris | last post by:
When a request comes into a page on my ASP.net site and a session is not found, I want to detect whether the request is an initial request or if the user did have a session going that has now been...
5
by: Åženol Akbulak | last post by:
Hello; I use in my web application FormsAuthentication. Also I use Session state (InProc). When a user logged in, I can read Session parameters. (For example Session). Problem is that, when...
13
by: Goofy | last post by:
Does anyone know how I can kill a session by session ID ? -- Goofy
4
by: rgparkins | last post by:
Hello I am running out of time with a problem I have running PHP 5.04 and Apache 2.0 and really need help :(. I have a page that stores a variable in session but each time I reload that page the...
2
by: Gordon Burditt | last post by:
I had this idea about preventing session fixation, and I'm wondering what anyone else thinks about it. The idea is, essentially, don't allow session ids that YOUR PHP didn't generate (and aren't...
9
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.