473,657 Members | 2,524 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 1526
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
3589
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 np longer pops up. I think it is irritating to users to have to close the popup everytime they visit the page. I think I need to set a cookie so that the server knows the visitor is a return visitor and not a new visitor, but I have no idea how to...
3
1942
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 should be avoided; due to use of popup blockers and browser that do not process javascript. Is the use of popup windows bad design? Will it severly reduce the usage of our web page?
4
22187
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 description and a class_id (stored in the value attribute of each option). The user will then select a class from the drop-down list. What I want to do is have a control in the parent browser window which can store the class_id and the...
15
10089
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 popup has a DataGrid on it and the page.load function DataBinds as you'd expect. I have Code-Behind in C# to emit a call to a JavaScript function which
7
4723
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 regarding the popup works perfectly, it pops up with the correct data. But the strange thing is now any link that targets the iframe simply get ignored and instead of displaying things in the iframe they get displayed in a new browser window...
2
3260
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 validated my HTML and CSS code. 1. When I clear cache and refresh my webpage, it takes 3 tries before the popup window displays - I click on the button once, a white window the size of my webpage displays. I close it and click on the button again (for...
5
1959
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 and CSS code. 1. When I clear cache and refresh my webpage, it takes 3 tries before the popup window displays - I click on the button once, a white window the size of my webpage displays. I close it and click on the button again (for the same...
2
1796
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 out. The count down timer on popup will start with 120 and will be count down to 0 and if the user doesn't click on the Continue button (which is on popup), application logs out and the web page will be shown with login page. If the user clicks...
11
5289
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. How do I submit that form1 from the javascript from my current window? Thanks.
3
4276
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, once the popup window re-loads itself by posting a form to itself, all Javascript state information is lost and so opener is undefined. Is there any way I can communicate with the original opener of a popup window once the popup window has been...
0
8740
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.