1 Reply Latest reply: Oct 16, 2013 4:58 AM by Hari_639 RSS

    Closing All Pop Up Windows

    Gus C

      Apex 3.2

       

      I have a page where the user can click report links and open popup pages.

      When I navigate away from the report page, I would like to ensure that all popups have been closed.

      I have found this javascript for the purpose

      <script>

      function closeChildWindows() {

          for (var loop=0; loop<childWindowHandles.length; loop++)

          {

           if (!childWindowHandles[loop].closed)

           {

            childWindowHandles[loop].close();

           }

          }

      }

      </script>

       

      My problem is, that I do not have a cancel button to attach it to.

      Is there a way to fire the script when I navigate away from the page.

       

      Regards

       

      Gus

        • 1. Re: Closing All Pop Up Windows
          Hari_639

          Hi Gus,

           

          You can execute your JS during page unload of report page. (parent page)

           

          <script type="text/javascript">
          window.onunload = closeChildWindows;
          function closeChildWindows() {
              for (var loop=0; loop<childWindowHandles.length; loop++)
              {
               if (!childWindowHandles[loop].closed)
               {
                childWindowHandles[loop].close();
               }
              }
          }
          </script>
          
          

           

          See onunload Event

           

          Regards,

          Hari