Question: I opened a popup window by window.open in JavaScript, I want to refresh parent page when I close this popup window.(onclose event?) how can I do that?

```
window.open("foo.html","windowName", "width=200,height=200,scrollbars=no");

```

Answer: 
on your child page, put these:

```
<script type="text/javascript">
    function refreshAndClose() {
        window.opener.location.reload(true);
        window.close();
    }
</script>

```

and

```
<body onbeforeunload="refreshAndClose();">

```

but as a good UI design, you should use a Close `button` because it's more user friendly. see code below.

```
<script type="text/javascript">
    $(document).ready(function () {
        $('#btn').click(function () {
            window.opener.location.reload(true);
            window.close();
        });
    });
</script>

<input type='button' id='btn' value='Close' />

```
window.open will return a reference to the newly created window, provided the URL opened complies with [Same Origin Policy](http://www.mozilla.org/projects/security/components/same-origin.html). 

This should work:

```
function windowClose() {
    window.location.reload();
}

var foo = window.open("foo.html","windowName", "width=200,height=200,scrollbars=no");
foo.onbeforeunload= windowClose;​

```