Click to See Complete Forum and Search --> : Close All Popups


azi_1
July 29th, 2005, 02:49 PM
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();}}
}

olivthill
July 29th, 2005, 03:10 PM
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:

//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();}}
}

azi_1
July 29th, 2005, 04:01 PM
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();}}
}

Dr. Script
July 29th, 2005, 04:14 PM
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.

azi_1
August 1st, 2005, 12:56 PM
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();
}

Dr. Script
August 1st, 2005, 04:26 PM
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.