Closing Child Popup Windows When Parent Window is Closed

Hi friends .
  Few days ago , i faced a problem with my project , that i need to close all the child popups when parents window is closed . some time we missed this check but we have to follow this in our common practices.
Here I am placing a code regarding to my issue . hope this will help you .

for example ,
 
Here is the code to open a new window:
<script type="text/javascript">
        var arrPopups = new Array();// create an array of popup window object
//This is a java script function used for open a popup window in which we maintain a array with all the child window names .
     function openPopUp(pageUrl,pageName) {
var popUpObj = window.open(pageUrl, pageName,                                                            "width=600px,height=500px,resizable,toolbar=false, scrollbars");
              arrPopups .push(popUpObj );
        }
//Here is the function for closing all the child windows which is maintain by array .
  function closePopUps() {
            if (arrPopups.length == 0) return;

            for (i = 0; i < popups.length; i++) {
                arrPopups [i].close();
            }
        }
    </script>

finally call this function on body onunload
like this,
<body onunload="closePopUps()">

If you refresh the parent  window through the child window from server side use this code

 Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.opener.document.forms[0].submit();self.close();</script>");

Hope this will helps you..

Regards ,
Rajesh 

0 comments: