473,503 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

popup once

1 New Member
Hi

i have a popup which appears once when the page is opened and then the cookie is deleted on the no of days mentioned, but here i need to change it on the session basis, i;e when the page is closed event the cookie as to be deleted. Below is what the code i have been using. Please help me out on this.

Thanking You,
Regards,
Shiv.


Expand|Select|Wrap|Line Numbers
  1. var expDays = 1; // number of days the cookie should last
  2.  
  3. var page = "Popup.html";
  4. var windowprops = "width=345,height=335,location=no,left=180,top=300,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
  5.  
  6. function GetCookie (name) {
  7.   var arg = name + "=";
  8.   var alen = arg.length;
  9.   var clen = document.cookie.length;
  10.   var i = 0;
  11.   while (i < clen) {
  12.     var j = i + alen;
  13.     if (document.cookie.substring(i, j) == arg)
  14.     return getCookieVal (j);
  15.     i = document.cookie.indexOf(" ", i) + 1;
  16.     if (i == 0) break;
  17.   }
  18.   return null;
  19. }
  20.  
  21. function SetCookie (name, value) {
  22.   var argv = SetCookie.arguments;
  23.   var argc = SetCookie.arguments.length;
  24.   var expires = (argc > 2) ? argv[2] : null;
  25.   var path = (argc > 3) ? argv[3] : null;
  26.   var domain = (argc > 4) ? argv[4] : null;
  27.   var secure = (argc > 5) ? argv[5] : false;
  28.   document.cookie = name + "=" + escape (value) +
  29.     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  30.     ((path == null) ? "" : ("; path=" + path)) +
  31.     ((domain == null) ? "" : ("; domain=" + domain)) +
  32.     ((secure == true) ? "; secure" : "");
  33. }
  34.  
  35. function DeleteCookie (name) {
  36.   var exp = new Date();
  37.   exp.setTime (exp.getTime() - 1);
  38.   var cval = GetCookie (name);
  39.   document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  40. }
  41.  
  42. var exp = new Date();
  43. exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
  44.  
  45. function amt(){
  46.   var count = GetCookie('count')
  47.   if(count == null) {
  48.     SetCookie('count','1')
  49.     return 1
  50.   } else {
  51.     var newcount = parseInt(count) + 1;
  52.     DeleteCookie('count')
  53.     SetCookie('count',newcount,exp)
  54.     return count
  55.   }
  56. }
  57.  
  58. function getCookieVal(offset) {
  59.   var endstr = document.cookie.indexOf (";", offset);
  60.   if (endstr == -1)
  61.   endstr = document.cookie.length;
  62.   return unescape(document.cookie.substring(offset, endstr));
  63. }
  64.  
  65. function checkCount() {
  66.   var count = GetCookie('count');
  67.   if (count == null) {
  68.     count=1;
  69.     SetCookie('count', count, exp);
  70.     window.open(page, "", windowprops);
  71.   } else {
  72.     count++;
  73.     SetCookie('count', count, exp);
  74.   }
  75. }
  76.  
  77. window.onload=checkCount;
Mar 10 '08 #1
1 1522
acoder
16,027 Recognized Expert Moderator MVP
Call DeleteCookie() onunload.
Mar 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3586
by: David Graham | last post by:
Hi I use an OnLoad event in the body tag to open a popup window. I would like to know how to go about only allowing the window to popup once i.e on subsequent visits to the parent page, the popup...
3
1932
by: Dan | last post by:
First, I'm sorry if this question has been asked too many times. I'm new to this news group. The question has to do with the use of popup windows in a web page. I have heard that popup windows...
4
22156
by: Davey | last post by:
I have a website which has a popup window (this only opens when the user chooses to open it). In the popup window I have a <select> control which lists a selection of "classes". Each class has a...
15
10053
by: H00ner | last post by:
Hello All Hope you can help Been pulling my hair out about a popup problem in ASP.NET. One of the forms i wrote requires the user to select a product from a list in a popup web form. the...
7
4690
by: ukrbend | last post by:
I use an iframe on my home page and everything works perfectly. But now I decided to add a popups to my page. The popups come not from within the iframe but from the parent frame. Again, everything...
2
3222
by: wreed06 | last post by:
Hello, I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully...
5
1950
by: wreed06 | last post by:
I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully validated my HTML...
2
1786
by: =?Utf-8?B?U3VyZXNoIFJlZGR5?= | last post by:
I am getting a strange problem with IE7 tabs. The web application I am working (developed in ASP.Net, .Net 2.0), will show a popup message with the count down timer 2 minutes before session time...
11
5264
by: V S Rawat | last post by:
using Javascript, I am opening a web-based url in a popup window. MyWin1=Window.Open(url, "mywindow") There is a form (form1) in the url in that popup window, I need to submit that form. ...
3
4248
by: Bruce | last post by:
I have an application where a main window opens a popup window. Within the popup, I want to be able to post a form back to the popup all the while maintaining the opener property. Of course,...
0
7205
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
7093
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
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7353
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...
1
7011
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...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.