Web Analytics Made Easy -
StatCounter Close all popups when exiting the main page - CodingForum

Announcement

Collapse
No announcement yet.

Close all popups when exiting the main page

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Close all popups when exiting the main page

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

  • #2
    popup.js:
    Code:
    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:
    Code:
    function closeAllPopups(){
      closePopup("winCalc");
      closePopup("winHelp");
    }
    
    function closePopup(popupHandle){
      if (window[popupHandle] && !window[popupHandle].closed){
         window[popupHandle].close();
      }
    }
    window.onunload = closeAllPopups;
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      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() >

      Comment


      • #4
        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.
        Glenn
        vBulletin Mods That Rock!

        Comment


        • #5
          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();
          }
          }

          Comment


          • #6
            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:
            Code:
            function calcWindow() {
              var winCalc = window.open("Calculator/SciCalc.htm", "[B]calcPopup[/B]", "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", "[B]helpPopup[/B]" ,"height=500,width=550,status=yes,toolbar=no,menubar=no,location=no");
              winHelp.focus();
            }
            main page:
            Code:
            function closeAllPopups(){
              closePopup("[B]calcPopup[/B]");
              closePopup("[B]helpPopup[/B]");
            }
            
            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.
            Glenn
            vBulletin Mods That Rock!

            Comment


            • #7
              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!!!

              Comment

              Working...
              X