+ Start a Discussion
RovRov 

Closing the popup Visualforce page and refreshing the page that opened the popup


I have a VFp , which open another VFP as a popup, after the pop is closed, i want the parent page that opened the popup to be refreshed. 

My code/javscript  closes the VFP popup but it doesnt reload the parent page. I have to manually reload the parent page to see the updated record.

Note:  The reason i am using window.open is becuase i want users to have the ability to scroll through the parent window. 

Any suggestions????


**********************************************************************************************************************
VFP1

<script type="text/javascript">
function OpenVfpage(){
window.open('/apex/SendEmailPage?id={!recordId}', '_blank','scrollbars=yes,width=600,height=800,resizable=no,toolbar=0,location=0,menubar=0');
}
</script>

<apex:commandButton value="Send Email" id="email" onclick="javascript:OpenVfpage();"/>

**********************************************************************************************************************


VFP2

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

if("{!$Request.success}" == "true") {
parent.window.close();
window.close();
        
}
</script>

<apex:commandButton id="saveBtn" value="Send" action="{!sendEmail}" onComplete="javascript:closeVFP();"/>


**********************************************************************************************************************
Controller

public PageReference sendEmail(){
// logic to send the email
return new PageReference ('javascript:window.close()');

}
Saurabh DhobleSaurabh Dhoble
In the parent window, add this method --
function popupClosed() {
    window.location.reload();
}
In the popup window, add this --

window.onunload = function() {
    if (window.opener && !window.opener.closed) {
        window.opener.popUpClosed();
    }
};
This will refresh the parent whenever your popup is unloaded/closed. You can remove the parent.window.close() line from your code.
Please mark this as answer if this answered your question.
Saurabh DhobleSaurabh Dhoble
Did this work ?
RovRov
unfortunately no. parent page doesn't get refreshed. I tried many different approaches but nothing i have tried refreshes the page.
Jai ChaturvediJai Chaturvedi
On your child page call following javascript:

<apex:page>
<script type="text/javascript">
    function closeWin(){    
        if(window.parent){
            window.parent.opener.location.href = window.parent.opener.location.href;
            window.parent.close();
        }   
        else{
            window.opener.location.href = window.opener.location.href;
            window.close();   
        }   
    }
    function closeWindow_NoAction(){
        window.close();
    }
</script>

<apex:commandButton value="Save" action="{!saveRecord}" oncomplete="closeWin();" />
<input type="button" class="btn" value="Cancel" onclick="closeWindow_NoAction();"/>

</apex:page>

Let me know if this works.