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 ..

MiddhaMiddha

Hey Sheffy,

 

It depends, if the parent window is a Vf page and your child window is also a VF page, than you can refresh the parent window because your both the pages are on same domain.

 

In case you want to refresh the standard salesforce page (parent page) from a custom VF page (child page), this wont happen as salesforce saves it standard application pages on a different domain than Vf pages.

 

Try this:

 

 

<script> 
    window.close();
    window.opener.location.href = window.opener.location.href;   
</script> 

 

 

SheffySheffy

This is not working... :(

MiddhaMiddha

Are you getting any error?

 

Can you confirm if the parent window is a VF page and what is the URL of your parent window and child window?

SheffySheffy

not an error,

but crome going to stop work i.e. I'm not able to click anywhere in different tab.

 

url is same ...

Imran MohammedImran Mohammed

When you open the child window, you can assign it to a variable like

 

var childWin;//declare global

var intervalId;// declare global

 

//Code to invoke the popup

childWin = window.open(URL);

intervalId = window.setInterval('checkIfChildWindowIsClosed()', 5*1000);

 

//add thios function

function checkIfChildWindowIsClosed()

{

   if(childWin.close())

   {

       window.clearInterval(intervalId);

       window.parent.location.href = window.parent.location.href;

   }

}

 

Let me know if you have any questions

Imran MohammedImran Mohammed

To remind, add the code i posted into the javascript code of your parent and not the child.

From Childs code remove opener.location.reload(true);

 

Even though standard pages are hosted on different domains, they can still be refreshed from VF page.

LakshmanLakshman

Imran,

 

Can you please tell me how can I refresh standard page layout from VFP. I am involving VFP by onclick Javascript function and calling my page by showmodaldialog.

Please let me know how can I refresh standard page layout from this pop up when I save a record.

Thank you!

 

Regards,

Lakshman

jon-wujon-wu

Any luck? I'm having the same problem. It doesn't seem like there's any way to do this since it's cross domain - unless Salesforce opened up some sort of cross domain way to tell the parent to refresh.

 

Am I missing something?

kevingwynnkevingwynn

I worked with 

//Get SFID from URL
var sfid = location.href.replace(/^.*salesforce\.com\/([^\/]+).*$/, '$1');
window.childWin = window.open('/apex/ApplyChecklistTemplate?id=' + sfid, 'ApplyChecklistTemplate', 'height=550,width=750,location=yes,menubar=no,status=no,toolbar=no');
window.intervalId = window.setInterval('window.checkIfChildWindowIsClosed()', 5*1000);
 
//add check function to window
window.checkIfChildWindowIsClosed = function()
{
    if(window.childWin.closed)
    {
        window.clearInterval(window.intervalId);
        window.parent.location.href = window.parent.location.href;
    }
}

 This works pretty well for me. Though, sometimes the 5-second interval seems too long... i might shorten it up a bit to make it flow better.

SKiran.ax1878SKiran.ax1878

Here is the solution to your problem and also it considers cross domain issues.

http://techstuffdiary.blogspot.in/2013/10/reloading-parent-window-on-close-of.html

Thanks!!!!

Jerry ClifftJerry Clifft
kevingwynnkevingwynn your solution works great for me, thanks! Cross domain, cross object...
r@hulr@hul
Thanks !!
but using above method..(Croos domain)
I am getting error like object doesn't support this property or method in IE