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
SheffySheffy 

Close The PopUp(Child Window) and refresh Parent Window ?

HI,

I want to know that how would i refresh Parent Window on Clicking of Save/Submit button on PopUp window or we can say Child window.

For this I used JavaScript :

 

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

      opener.location.reload(true);
      self.close();
  }
</script>

On Submit :

 

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

 

But It doesn't Work .

Please Help ..

 

 

Best Answer chosen by Admin (Salesforce Developers) 
b-Forceb-Force

As Salesforce.com standard pages and Visual force pages are running on seperate domains,

 

so there will be some issue for calling javascript from cross domain.

 

 

you can try below code snippet,

 

pass your recordId to VF page as query string param.

 

 

<script language="JavaScript" type="text/javascript">

function CloseAndRefresh(){

window.opener.location.href="/{!$CurrentPage.parameters.PARAMNAME}";

      self.close();
  }
</script>

 

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

 

 

Hope this will help you as workaround.

 

 

Thanks

Bala

 

 

 

 

 

All Answers

b-Forceb-Force

As Salesforce.com standard pages and Visual force pages are running on seperate domains,

 

so there will be some issue for calling javascript from cross domain.

 

 

you can try below code snippet,

 

pass your recordId to VF page as query string param.

 

 

<script language="JavaScript" type="text/javascript">

function CloseAndRefresh(){

window.opener.location.href="/{!$CurrentPage.parameters.PARAMNAME}";

      self.close();
  }
</script>

 

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

 

 

Hope this will help you as workaround.

 

 

Thanks

Bala

 

 

 

 

 

This was selected as the best answer
Naresh Krishna.ax1176Naresh Krishna.ax1176

Hi,

 

I have similar problem.

 

What would be the value of below:

{!$CurrentPage.parameters.PARAMNAME}

 

Thanks.

Naresh Krishna.ax1176Naresh Krishna.ax1176

Below is my code:

 

Parent page:-

 

function fnSearchSelect() {
        var w = 650;
        var h = 600;
        var left = (screen.width/2)-(w/2);
        var top = (screen.height/2)-(h/2);              
        window.open('/apex/SearchAndSelect',
                        'selectResource',
                        'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=false, copyhistory=no, width='
                                + w
                                + ', height='
                                + h
                                + ', top='
                                + top
                                + ', left=' + left);
    }

 

<apex:commandLink style="text-decoration:none;background-image:none;" onclick="fnSearchSelect();"> 

Search

</apex:commandLink>

 

Popup window:- (/apex/SearchAndSelect)

 

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

 

<apex:commandLink value="Select" style="color: #107CA2;" onclick="CloseAndRefresh()"                                          
</apex:commandLink>

<apex:inputHidden id="TextValue" value="{!selectedResource}"/>

 

Result:-

Window was not closed.

 

Could you please help me with the below:

1. popup window should be closed.

2. the value {!selectedResource} in the popup need to be fetched in the parent page.

 

Thanks.

Sure@DreamSure@Dream

Hi using commandlink, i am opening a new window from a vf page.

After performing some operations in the child window. I am closing that window using a commandbutton.

On closing the child window, i want to refresh the parent window.

I have tried in the way that is mentioned in this post, but its throwing an error, "Unknown Property 'StandardController.CurrentPage'".

 

Pls help me with this.

 

Thanks,

snyakasnyaka

In your pop-up visual force page add this to the function that is called when the close button is clicked  - 

 

p = new PageReference('javascript&colon;window.opener.history.go(0);self.close();');

p.setRedirect(true);

 

It works perfectly for me..