Click to See Complete Forum and Search --> : How to close all windows when exiting the main page


azi_1
July 27th, 2005, 03:03 PM
I have a MainPortal.jsp. From the mainportal user can click on a button which goes to RefPortal.jsp. In the RefPortal page I have buttons that open new html files. Is it possible for the open html files to also close when the user clicks on Exit in the MainPortal?
Would appreciate any help.

//This is the code in MainPortal to Exit the program...this only closes the main program and not the open html file
<a href="#" onClick="javascript:top.window.close()" ><IMG SRC="/images/PORTALS/t_67.gif" WIDTH=161 HEIGHT=33
name="t_67" border="0" ALT="EXIT">

//Here is the code in RefPortal that opens a new html file
<TD width="161"><a href="../Library/libraryPopFrame.htm" ><IMG SRC="/images/PORTALS/t_223.gif" WIDTH=161 HEIGHT=33
name="t_223" border="0" ALT="LIBRARY">

PeejAvery
July 30th, 2005, 07:27 PM
Does this have anything to do with your other post about closing windows on exit? If so, you should ask a moderator to merge them.

You can use the onunload command to do things in your main window on exit. Just tell it to close the window tags onunload.

azi_1
August 1st, 2005, 01:08 PM
This is a bit different than the other post. I was trying to have all popups close when the user exits the main program. But the popups are called from child pages of the main program. Calling close window tag onUnload on popups only seems to close the popups when user exits the current page.Thanks.

PeejAvery
August 2nd, 2005, 08:39 AM
Do you mean when a user changes the URL of the parent window?

If that is the case, you can paste this code in your child windows.

<script language="JavaScript">
function checkurl(){
url = "*MAIN PAGE URL HERE*";
if(parent.location<>url){
*CLOSE CHILD WINDOW SCRIPT HERE*}
setTimeout("checkurl()", 100);
}
</script>

azi_1
August 2nd, 2005, 12:04 PM
Thanks for your reply. I will try to explain the situation better.
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. I am able to close all the popups when the user clicks "Back to main" on the child page when I place the below code in the child page. I don't know if it's possible for the popups to close when the user clicks on Exit in the main page. Is there a way for main.jsp to reference to winTt and function closeAllPopups?


//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()" >


//This is the code in my child page

var winTt;
function torque(myname, w, h, scroll)
{

winTt=window.ope("/RefDocs/OTIS/torque/torqueFrame.jsp",myname, winprops,"toolbar=no, location=no, directories=no,\
status=no, menubar=no,copyhistory=yes");
winTt.focus();
}

function closeAllPopups(){
closePopup("winTt");
}

function closePopup(popupHandle){
if (window[popupHandle] && !window[popupHandle].closed){
window[popupHandle].close();}
}
window.onunload = closeAllPopups;

PeejAvery
August 2nd, 2005, 06:03 PM
Just put your function in a *.JS file and call that file as a script. From there, any document can run it.

azi_1
August 3rd, 2005, 10:46 AM
Thanks.
I made a .js file for the popup. I added the closeAllPopup function to my main.jsp page. When the user clicks on Exit from the main page, I call the function CloseAllPopup. When I run this code and click on Exit, none of the windows(main window/ popups) get closed. Please let me know if you can see why this is happening.

///////////The following code is in acc.js file.///////////////////////////////////
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 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();}

//////////////////The following code is in Main.jsp//////////////////////
<script LANGUAGE='JavaScript' src='/ACC/acc.js'></script>
function closeAllPopups(){

closePopup("winCalc");
closePopup("winHelp");
closePopup("winCaln");
closePopup("winTpdr");
closePopup("winCp");
closePopup("winVv");
window.close(); // To close the main window
}

function closePopup(popupHandle){
if (window[popupHandle] && !window[popupHandle].closed){
window[popupHandle].close();
}
}
window.onunload = closeAllPopups;

//Exit button needs to close all windows and main window/////////
<a href="#" onClick="closeAllPopups()" >

PeejAvery
August 3rd, 2005, 02:17 PM
First of all, try using CODE tags. It will help others to read it more clearly.

Are you sure that it is running this *.JS file from the main page? The following works for me. Remember to put ALL your JavaScript in the JS file and don't leave any on the JSP page. Then call it from your JSP page.

JSP Page:
<html>
<body onunload="closeAllPopups()">
<script src="script.js"></script>
</body>
</html>
JS Script:
var winCalc;
var winHelp;

function calcWindow(){
url = "http://www.yahoo.com";
wp = "height=300,width=350,status=yes,toolbar=no,menubar=no,location=no";
winCalc = window.open(url, "calc", wp)
winCalc.focus();
}

function helpWindow(){
url = "http://www.google.com";
wp = "height=500,width=550,status=yes,toolbar=no,menubar=no,location=no";
winHelp = window.open(url, "help", wp)
winHelp.focus();
}

function closeAllPopups(){
closePopup("winCalc");
closePopup("winHelp");
closePopup("winCaln");
closePopup("winTpdr");
closePopup("winCp");
closePopup("winVv");
}

function closePopup(popupHandle){
if (window[popupHandle] && !window[popupHandle].closed){
window[popupHandle].close();}
}

azi_1
August 3rd, 2005, 05:13 PM
Thanks. I used the same code as above in my files. In my .jsp file when I use <BODY onunload="calcWindow()"> I see the calculator window popup on exiting the main page, so it seems that onunload is able to access the .js file. But when I use <BODY onunload="closeAllPopups()">, none of the popups close when I exit the main page. It seems to not go through closeAllPopups function....

//.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(){
closePopup("winCalc");
closePopup("winHelp");
}

function closePopup(popupHandle){
if (window[popupHandle] && !window[popupHandle].closed){
window[popupHandle].close();
}
}

PeejAvery
August 3rd, 2005, 06:19 PM
Attached is a rendition of your script I re-wrote and it works completely on my computer. Try it out on yours and if it works for you, use it.

azi_1
August 4th, 2005, 10:18 AM
Thanks for the sample script.
I compared it with my code and I noticed the only difference was that my code was missing:
<script language="JavaScript">
setTimeout("win1()", 1);
setTimeout("win2()", 1);
</script>

Without using setTimeout() in my Main.JSP file, the popups do not close on exiting the main page.
If I add setTimeout() the popups close but everytime the main page loads and unloads the popups open even if the user does not click to open the popups. Do you know if it is possible for popups to close in the main page without this problem? Thanks.

PeejAvery
August 4th, 2005, 07:20 PM
Glad all worked out. Don't forget to rate posts if they are helpful.