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
Karthik SankarKarthik Sankar 

Problem with refreshing the parent window using javascript in visualforce page

I have a simple usecase of opening a new window while clicking a custom button in a detail page record, closing it immediately and then refreshing the parent window (from which the new window was opened).

This functionality works fine when I use javascript in S-Control for closing the current window and refreshing the parent window. The sample code below:

<html>
<script>
function reSizeWindow()
{
refreshWindow();
top.window.close();
}
function refreshWindow()
{
opener.location.reload();
}
</script>
body onload="reSizeWindow();">
<center>
<br><br><br>
<SPAN STYLE=" font-size: 75%; font-family: 'Arial', 'Helvetica', sans-serif;">
Updating Account and Contact Information... Please Wait.
</span><br><br>
<img src="/img /waiting_dots.gif " alt="Please wait..." title="Please wait..." height="20" width="196">
</center>
</body>
</html>

But when I convert this to a visualforce page, the javascript code to refresh the parent window doesn't work. The sample code for vf page below:

<apex:page standardController="<custom_obj__c">
<script>
window.onload = function()
{
refreshWindow();
top.window.close();
}
function refreshWindow()
{
opener.location.reload();
}
</script>
</apex:page>

If I remove the refreshWindow() function, then the closing of current window is working fine but the opener.location is not recognized in this page.

This usecase may look unnecessary, but the actual implementation would be some updation happening in the controller and returning back to the same page.

Any suggestion regarding any workaround to refresh a parent window in visualforce or let me know if I am missing something.

Regards,
Karthik.
Anand@SAASAnand@SAAS

About two releases ago, the domain from which visual force pages were served was changed to "c.naX.visual.force.com" Cross domain security that is enforced by most browsers will come into play when you try to access the parent window which is in a different domain. 

 

Have you looked at the javascript errors in Mozilla/Chrome as to what the exact error is? 

Karthik SankarKarthik Sankar

Hi Anand,

 

I checked the js code with Firebug in Mozilla and it is showing error as 'opener is null', meaning its not able to identify the parent window.

 

But I hope opener is the only way used to identify the parent window in js. I am not sure of any other way to do this.

 

Do you have any code example on achieving this in vf???

 

Thanks,

Karthik.

Karthik SankarKarthik Sankar

Hi Anand, I have got this working. Its just a single line of code which I missed trying before. Just got it by trial method. 

 

<script>

function closeWindow()

{

 top.window.close();

 parent.window.opener.location.reload();

}

</script>

 

Thanks,

Karthik.

Anand@SAASAnand@SAAS
Interesting. So it was really not a cross-domain browser issue after all.
sfdccoder1sfdccoder1

 

I think it is a cross-domain browser issue.

I have the same problem at what you are saying make sense.

What doesn't make sense is Karthik Sankar's last post.

Karthik - are you sure you are refreshing a parent window from a different domain?

Browsers don't allow that.