This discussion is archived
1 Reply Latest reply: Oct 16, 2013 2:58 AM by Hari_639 RSS

Closing All Pop Up Windows

Gus C Journeyer
Currently Being Moderated

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 Guru
    Currently Being Moderated

    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

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points