Sunday, 15 January 2012

Close Popup and refresh parent window

It is 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:

<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(){

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.


  1. This is working fine is chrome and firefox. But it is not working for IE

  2. It also doesn't work if you have a visualforce page opened by a standard salesforce page.

    1. You can solve this problem when you have visualforce page opened by a standard salesforce page.

    2. Even the code in above link doesn't work in IE as it opens a new tab.

  3. do the following in google chrome if you have VF page open:'', '_self', '');