My requirement is whenever user clicks on some custom button on child window, that window gets closed plus the parent page should be refreshed.

But only child window is getting closed and parent window is not getting refreshed.

Following is the code snippet i am using in child vf page:

<apex:commandButton action="{!Save}" onclick="javascript:CloseAndRefresh()" value="Save"/>

<script language="JavaScript" type="text/javascript">
        function CloseAndRefresh(){

Any suggessions??

  • Does that work on non-visualforce pages ? If the problem isn't visualforce related, and pure Javascript you may be better of askign this at stackoverflow. Jun 4, 2014 at 20:52

4 Answers 4


Can you try this

function CloseAndRefresh(){

For anyone looking at this post for a solution, the response posted by Jai Chaturvedi here (May 27, 2014 - 5th post from top) worked for me. Good luck!


If you have some parameter that is passed to popup window, you can reload parent window using the below script,

      function closeWindow(){      

In my case I am passing Id of the record as parameter to the popup window. Make sure that "Developer Mode" is not enabled. If it is enabled, it will not work.


I too stuck in a similar issue, I am calling a visualforce page from a javascript button, button's code is as

window.open('/apex/addNaratives?id={!Lead.Id}&retURL=/apex/ForceWindowClose', 'Popup Name' ,"width=700, height=580, scrollbars=yes")

it is opening a new window as desired, id also being passed, now I want this, once the button on this visualforce page "Save" record which actually saving this record, is clicked the javascript window should close and it should redirect me to the Narrative detail record page. visualforce page code is as

<apex:form >
<apex:pageBlock mode="edit" title="The Insurance Agency, Inc">
<apex:pageblockButtons location="bottom">
<Apex:commandButton value="Save" action="{!saveRecord}" />

The narrative should answer the following topics to validate the information gathered and provide for others
a comprehensive understanding of the agency.


<apex:pageBlockSection columns="1" title="Add Narrative" >
<apex:inputtextarea value="{!Nar.History__c}" label="History" cols="80" rows="6"  required="true"/>
<apex:inputtextarea value="{!Nar.Operational_Summary__c}" label="Operational Summary" cols="80" rows="6"  required="true"/>
<apex:inputtextarea value="{!Nar.Needs_Analysis__c}" label="Needs Analysis" cols="80" rows="6"  required="true"/>
<apex:inputtextarea value="{!Nar.History__c}" label="Conclusions" cols="80" rows="6"  required="true"/>


  • 1
    Welcome to SFSE! Please take the tour and read How to Ask and How to Answer. Your answer is in one or two of the review queues, and I'm not sure that this actually answers the question. If you intended for this to be an answer to the question, please edit your answer to make it more clear how this answers the question. If this isn't an answer, but rather a question of your own, please make your own question.
    – Derek F
    Dec 24, 2018 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .