Pages

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

5 comments:

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

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

    ReplyDelete
    Replies
    1. You can solve this problem when you have visualforce page opened by a standard salesforce page.
      http://techstuffdiary.blogspot.in/2013/10/reloading-parent-window-on-close-of.html

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

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

    ReplyDelete