Close popup and refresh parent window in Visualforce Page

Its a very common requirement to open a pop up by clicking a button . Once you are done with pop up, close the pop up and refresh the parent window so that user will be able to see the update on parent window at the same time.

Here is the sample code for it:

Command button in Visualforce Page:

<apex:commandbutton action="{!save}" id="button" oncomplete="javascript:CloseAndRefresh()" value="Update"/>

And here is the java script function:

<script language="JavaScript" type="text/javascript">
function CloseAndRefresh(){
window.opener.location.href="/{!$CurrentPage.parameters.id}";
window.top.close();

}
</script>

Note: I would suggest to check this setting Setup-> Personal Setup  ->  My Personal Information -> Personal Information
Here check for “Development Mode”. I have seen at various places and at community as well that if this check box is checked then popup would not close. Here, I would suggest to turn this checkbox off while you are testing this.