function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Scott0987Scott0987 

Issue with refreshing opener window and closing the popup window

I have a page that opens a popup window to input a new case comment.  when the comment is saved I want it to close the popup window and refresh the page that opened it so that it shows the new comment.   It just seems to do nothing.  I can replace the code that is supposed to reload the opener window with allert('afadsfdfa'); and it will popup an allert so I know the function is running.  

 

Here is the parent page:

<apex:tab label="Updates">
            <!-- script for poup window -->
            <script type="text/javascript">function newPopup(url) {popupWindow = window.open(url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')}</script>
            <!-- end script for poup window -->
            <apex:commandlink onclick="JavaScript&colon;newPopup('{!url}');" >Post Update
            </apex:commandlink>

 Here is the popup page:

<script language="JavaScript" type="text/javascript">
function CloseAndRefresh(){
    window.opener.location.reload(true);
    window.top.close();
}
</script>
<apex:form >
    <apex:outputlabel >Enter an update</apex:outputlabel><br />
    <apex:inputtextarea value="{!newUpdate}" rows="5" cols="35"/><br />
    <apex:commandbutton value="Cancel"/>
    <apex:commandButton value="OK" action="{!updteCase}" oncomplete="javascript&colon; CloseAndRefresh()" />
</apex:form>

 Thanks for any help you can give me. 

izayizay

I recently built something similar to mass update leads. In my case, the user selects leads from a list. When the user clicks a button to edit the selected leads, a pop-up window opons with the field to update. When the user clicks save in the pop-up window it updates the records, alert the user of successfull update and closes itself. While the pop-up is open, the parent window is listening for it to close. When the pop-up window closes, the parent window reloads. Here is the code:

 

JavaScript in parent window:

<script type="text/javascript">
    var editWindow;
    if(window.confirm("Edit Leads?")){
        editWindow = open("/apex/Mass_Edit_Leads?lids="+idsToUpdate , "Mass_Update_Leads", "height=300, width=300");
        var timer = setInterval(checkWindow, 500);
    }
    
    function checkWindow() {
        if (editWindow.closed) {
            //alert("Child window closed");   
            clearInterval(timer);
            window.location.reload();
        }
    }
</script>

 Pop-Up page:

 

<!-- include jQuery -->
<script type="text/javascript" src="{!URLFOR($Resource.jQuery)}"/>
<!-- The JavaScript Panel -->
<apex:outputPanel id="jsPanel">
    <script type="text/javascript">
        var j$ = jQuery.noConflict();
        j$(document).ready(function getResult(){
            var success = {!success};
            var error = {!error};
            var message = '{!errorMessage}';
            if(success == true){
                alert("{!leads.size} Leads Updated Successfully");
                window.open('', '_self', '');
                window.close();
            }else if (error == true){
                alert(message);
            }
        });
    </script>
</apex:outputPanel>

<!-- The pageblock -->
<apex:pageBlock id="myBlock" title="Mass Lead Edit">

    <!-- The pageBlockSection with the selected field for editting -->
    <apex:pageBlockSection title="Selected Field" columns="1" collapsible="false">
        <!-- The field to be editted -->
        <apex:inputField value="{!myLead[selectedField]}" required="false"/>
    </apex:pageBlockSection>
            
    <!-- The pageBlockButtons with save and cancel buttons -->
    <apex:pageBlockButtons location="bottom">
        <!-- Re-render jsPanel to get current values from controller -->
        <apex:commandButton value="Save" action="{!saveLeads}" reRender="jsPanel, myBlock"/>
        <apex:commandButton value="Cancel" onclick="javascript&colon;window.open('', '_self', '');window.close();"/>
     </apex:pageBlockButtons>

</apex:pageBlock>


 Hope this helps!