CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2005
    Posts
    24

    Close All Popups

    I need to close all popup windows when the user exits the main page.
    With my current code when user exits the main page after opening one popup the popup closes. But if I open both calculator window and help widow popups and exit the page, the popups don't close.

    Here is my code:
    //CALCULATOR Window
    function calcWindow() {
    var autoclose = true;
    win = window.open("Calculator/SciCalc.htm",null,"height=300,width=350,status=yes,toolbar=no,menubar=no,location=no")
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
    win.focus();
    if (autoclose) { window.onunload = function(){win.close();}}
    }

    //HELP Window
    function helpWindow() {
    var autoclose = true;
    win = window.open("/Help/Phoenix_Help/!SSL!/WebHelp/Phoenix_Help.htm",null,"height=500,width=550,status=yes,toolbar=no,menubar=no,location=no")
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
    win.focus();
    if (autoclose) { window.onunload = function(){win.close();}}
    }

  2. #2
    Join Date
    Jun 2005
    Posts
    1,255

    Re: Close All Popups

    The solution is to use different handles for your windows, and instead of having "win" and "win", you could have "win_calc" and "win_help", like this:
    Code:
    //CALCULATOR Window
    function calcWindow() {
    var autoclose = true;
    win_calc = window.open("Calculator/SciCalc.htm",null,"height=300,width=350,status=yes,toolbar=no,menubar=no,location=no")
    if (parseInt(navigator.appVersion) >= 4) { win_calc.window.focus(); }
    win_calc.focus();
    if (autoclose) { window.onunload = function(){win_calc.close();}}
    }
    
    //HELP Window
    function helpWindow() {
    var autoclose = true;
    win_help = window.open("/Help/Phoenix_Help/!SSL!/WebHelp/Phoenix_Help.htm",null,"height=500,width=550,status=yes,toolbar=no,menubar=no,location=no")
    if (parseInt(navigator.appVersion) >= 4) { win_help.window.focus(); }
    win_help.focus();
    if (autoclose) { window.onunload = function(){win_help.close();}}
    }

  3. #3
    Join Date
    Jul 2005
    Posts
    24

    Re: Close All Popups

    Thanks for your reply.
    I replaced "win" with "win_calc" and "win_help" but I don't see any difference with the result. Still when I open both popups they don't close when I exit the main page. Please let me know if there's something that I'm missing.
    Thanks.

    //CALCULATOR Window
    function calcWindow() {
    var autoclose = true;
    win_calc = window.open("Calculator/SciCalc.htm",null,"height=300,width=350,status=yes,toolbar=no,menubar=no,location=no")
    if (parseInt(navigator.appVersion) >= 4) { win_calc.window.focus(); }
    win_calc.focus();
    if (autoclose) { window.onunload = function(){win_calc.close();}}
    }

    //HELP Window
    function helpWindow() {
    var autoclose = true;
    win_help = window.open("/Help/Phoenix_Help/!SSL!/WebHelp/Phoenix_Help.htm",null,"height=500,width=550,status=yes,toolbar=no,menubar=no,location=no")
    if (parseInt(navigator.appVersion) >= 4) { win_help.window.focus(); }
    win_help.focus();
    if (autoclose) { window.onunload = function(){win_help.close();}}
    }

  4. #4
    Join Date
    May 2004
    Location
    MN / NJ, United States
    Posts
    768

    Re: Close All Popups

    Code:
    var help_open = false;
    var calc_open = false;
    var help_auto = false;
    var calc_auto = false;
    
    //CALCULATOR Window
    function calcWindow() {
    calc_open = true;
    calc_auto = true;
    win_calc = window.open("Calculator/SciCalc.htm",null,"height=300,width=350,status=yes,toolbar=no,menubar=no,location=no")
    if (parseInt(navigator.appVersion) >= 4) { win_calc.window.focus(); }
    win_calc.focus();
    }
    
    //HELP Window
    function helpWindow() {
    help_open = true;
    help_auto = true;
    win_help = window.open("/Help/Phoenix_Help/!SSL!/WebHelp/Phoenix_Help.htm",null,"height=500,width=550,status=yes,toolbar=no,menubar=no,location=no")
    if (parseInt(navigator.appVersion) >= 4) { win_help.window.focus(); }
    win_help.focus();
    }
    
    onunload = function() {
      if(calc_open && calc_auto)
        win_calc.close();
      if(help_open && help_auto)
        win_help.close();
    }
    Try that JavaScript. It uses global booleans to check whether the window is open (which could be done alternately, but this is just one way of doing it) and if you want it to be closed. The reason the other scripts fail is because you've got 2 onunload event handlers, and only one will run. My example has just one onunload event handler.
    *9-11-01* Never Forget; Never Forgive; Never Relent!
    "If we ever forget that we're one nation under God, then we will be a nation gone under." - Ronald Reagan

  5. #5
    Join Date
    Jul 2005
    Posts
    24

    Question Re: Close All Popups

    Thanks for your help. I tried using the following code, however there seems to be a problem. If I open help window first, then calculator window, the calculator window becomes the size of the help window(500,550) instead of size of the calculator window(300,350). It seems that by clicking on help and calculator instead of opening two windows, the two windows merge into one window.
    Please let me know if you can see the cause for this problem.

    var help_open = false;
    var calc_open = false;
    var help_auto = false;
    var calc_auto = false;

    //CALCULATOR Window
    function calcWindow() {
    calc_open = true;
    calc_auto = true;
    win_calc = window.open("Calculator/SciCalc.htm",null,"height=300,width=350,status=yes,toolbar=no,menubar=no,location=no")
    if (parseInt(navigator.appVersion) >= 4) { win_calc.window.focus(); }
    win_calc.focus();}

    //HELP Window
    function helpWindow() {
    help_open = true;
    help_auto = true;
    win_help = window.open("/Help/Phoenix_Help/!SSL!/WebHelp/Phoenix_Help.htm",null,"height=500,width=550,status=yes,toolbar=no,menubar=no,location=no")
    if (parseInt(navigator.appVersion) >= 4) { win_help.window.focus(); }
    win_help.focus();}

    onunload = function() {
    if(calc_open && calc_auto)
    win_calc.close();
    if(help_open && help_auto)
    win_help.close();
    }
    Last edited by azi_1; August 1st, 2005 at 01:29 PM.

  6. #6
    Join Date
    May 2004
    Location
    MN / NJ, United States
    Posts
    768

    Re: Close All Popups

    well, I can tell you, replace null in the window.open() statement to "_blank", which will have it open in a new window in every browser. For the 1 x 10 ^ -210 % of users thatuse Netscape 1.x, using null opens a window named null, instead of a new window.

    As for other problems, I'd probably have to see it online.
    *9-11-01* Never Forget; Never Forgive; Never Relent!
    "If we ever forget that we're one nation under God, then we will be a nation gone under." - Ronald Reagan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured