Ensuring auto-refresh of Standard page after updates in child popup custom Visualforce window – alternate solution

From the previous blog we understand that when we try to open the pop browser window from standard Salesforce record page, we are unable to refresh parent window/ standard Salesforce record page from popup as the application prevents cross site scripting.

In order to deal with the above issue, we previously suggested a workaround with the help bootstrap modal window. Let us look at an alternate solution for this issue here by using the following JavaScript written on PopButton.

abhishek June Blog

//Reference Variable for pop up window

varwindowRef;

varintervalId = 0;

 

functioncheckToOpenWindow()

{

windowRef= window.open(‘/apex/PopUp?id={!Test_Object__c.Id}’,’mydialog’,’width=750,height=500,scrollbars=yes,resizable=false’);

windowRef.moveTo(300,200)

checkWindowStatus();

};

setTimeout(checkToOpenWindow, 2*1000);

 

functioncheckWindowStatus()

{

intervalId = setInterval(checkAndCloseWin, 5*1000);

};

 

functioncheckAndCloseWin()

{

if(windowRef.closed)

{

clearInterval(intervalId);

parent.window.location.reload();

}

};

In the above code, we have created a referenceVar for child pop up window as VarwindowRef. The code setTimeout(checkToOpenWindow, 2*1000) will open the pop up window. The key here is when we are opening child window we are monitoring the status of child window through set interval function (javascriptinbuild function for timely event) as follows intervalId  =setInterval(checkAndCloseWin, 5*1000).

The above line code is checking the status of window in every 5*1000 seconds by calling checkCloseWin function. This is done with the following code –

functioncheckAndCloseWin()

{

if(windowRef.closed)

{

clearInterval(intervalId);

parent.window.location.reload();

}

};

This means if window is closed through our child window reference variable which is windowRef then it terminates the setInterval function through clearInterval(intervalId) function and refreshes the standard page or repeats the same function every 5 seconds.