Close Popup and refresh parent window in Salesforce




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

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

and here is the javascript function

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


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


Thanks.

Keep Reading.
Next Post Previous Post
No Comment
Add Comment
comment url