Close Popup Window and Refresh Parent Page

I needed this simple code tonight, I tried many ways, but this one worked perfectly. It firstly closes your popup window, and refresh the parent page then.

//close popup window and refresh the parent window
function CloseAndRefresh()
    if (window.opener && !window.opener.closed) {

You can use it like this:

<input type="button" class="button" onclick="CloseAndRefresh()" value="Close" />