How to close all windows when exiting the main page
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">
Re: How to close all windows when exiting the main page
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.
Re: How to close all windows when exiting the main page
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)
{
Re: How to close all windows when exiting the main page
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()" >
Re: How to close all windows when exiting the main page
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.
Re: How to close all windows when exiting the main page
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();
}
}
Re: How to close all windows when exiting the main page
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.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.