View Full Version : Close all popups when exiting the main page
a_sh1
08-02-2005, 12:01 AM
From the main page user can click on a button which goes to a child page. In the child page I have buttons that open several popups. Is it possible to close all popups when the user clicks on Exit in the main page?
Would appreciate any help.
//This is the code in Main page to Exit the program...I need this to close all popups and not only the main page(main.jsp)
<a href="#" onClick="javascript:top.window.close()" >
//Here is the code in the child page that opens popups(child.jsp)
<a href="javascript:calcWindow()" ...
<a href="javascript:helpWindow()"....
<a href="javascript:..................
<a href="javascript:..................
//This is the code in a file to open popups(popup.js)
function calcWindow() {
win = window.open("Calculator/SciCalc.htm",null,"height=300,width=350,status=yes,toolbar=no,menubar=no,location=no")
if (parseInt(navigator.appVersion) >= 4) { .window.focus(); }
win.focus();
}
function helpWindow() {
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();}
glenngv
08-02-2005, 03:57 AM
popup.js:
var winCalc, winHelp;
function calcWindow() {
winCalc = window.open("Calculator/SciCalc.htm", "calc", "height=300,width=350,status=yes,toolbar=no,menubar=no,location=no");
winCalc.focus();
}
function helpWindow() {
winHelp = window.open("/Help/Phoenix_Help/!SSL!/WebHelp/Phoenix_Help.htm", "help" ,"height=500,width=550,status=yes,toolbar=no,menubar=no,location=no");
winHelp.focus();
}
child page:
function closeAllPopups(){
closePopup("winCalc");
closePopup("winHelp");
}
function closePopup(popupHandle){
if (window[popupHandle] && !window[popupHandle].closed){
window[popupHandle].close();
}
}
window.onunload = closeAllPopups;
a_sh1
08-02-2005, 04:10 PM
Thank you very much for your reply. I tried the code and now all the popup windows close when I exit the child page. However, I need to have all the popups close when I exit the main page. Is it possible for the Main page to close all the popups?
Thanks.
//Here is how I currently exit the Main page
<a href="#" onClick="javascript:top.window.close() >
glenngv
08-03-2005, 02:53 AM
Isn't the onunload handler of the child frame also invoked when the top frame unloads? I tested it mine and it works. Try putting alert in closeAllPopups() function to see if it's being called.
a_sh1
08-04-2005, 12:03 AM
If I leave onunload="closeAllPopups()" in the .JS file, the popups all close when exiting the child page. But I need the popups to stay open until the user exits the main program. I removed onunload="closeAllPopups()" from the .JS code and placed it in the body tag of the main file. In my MAIN.jsp file when I use <BODY onunload="closeAllPopups()">, none of the popups close when I exit the main page. I used the alert message in closeAllPopups() and once I exit the main page, the alert message pops up so the onunload must be going through the closeAllPopups function, but it does not close the popups...
Thanks.
//MAIN.JSP CODE
<html>
<body onunload="closeAllPopups()">
<script LANGUAGE='JavaScript' src='/ACC/accmenu.js'></script>
<!-- Button to exit main page-->
<a href="#" onClick="javascript:top.window.close()">
</body>
</html>
//accmenu.JS
var winCalc;
var winHelp;
function calcWindow() {
winCalc = window.open("Calculator/SciCalc.htm","calc","height=300,width=350,status=yes,toolbar=no,menubar=no,location=no")
winCalc.focus();}
function closeAllPopups(){
alert('CLOSE ALL POPUPS');
closePopup("winCalc");
closePopup("winHelp");
}
function closePopup(popupHandle){
if (window[popupHandle] && !window[popupHandle].closed){
window[popupHandle].close();
}
}
glenngv
08-04-2005, 02:57 AM
So you open the popups from the child frame and want to auto-close them as the main page unloads and not as the child frame unloads?
popup.js:
function calcWindow() {
var winCalc = window.open("Calculator/SciCalc.htm", "calcPopup", "height=300,width=350,status=yes,toolbar=no,menubar=no,location=no");
winCalc.focus();
}
function helpWindow() {
var winHelp = window.open("/Help/Phoenix_Help/!SSL!/WebHelp/Phoenix_Help.htm", "helpPopup" ,"height=500,width=550,status=yes,toolbar=no,menubar=no,location=no");
winHelp.focus();
}
main page:
function closeAllPopups(){
closePopup("calcPopup");
closePopup("helpPopup");
}
function closePopup(popupTarget){
var win = window.open("", popupTarget, "width=10, height=10"); //get handle of the popup
if (win && !win.closed){
win.close();
}
}
window.onunload = closeAllPopups;
The caveat here is even if those popup windows are not open or already closed by the user when the main page unloads, 2 small popup windows will open and close quickly. There's nothing you can do about that. You can't get the window handle of the popup when the page that opens it has unload or refreshed, unless you try to open a new popup with the same target name.
a_sh1
08-04-2005, 07:06 PM
Yes, I want to be able to open the popups from the child frame and auto-close them as the main page unloads. I tried your code and all the popups close now.
Thanks so much for all your help!!!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.