Search code examples
javascriptsalesforceapex-code

Refreshing parent page refreshes child instead, Salesforce


I have a custom button on a page in salesforce, this button triggers a js code

 window.open("{!$Label.SF_Base_URL}/apex/DeletePageiFrame",300,300);

The DeletePageiFrame is an apex page that has an iframe(for an external website) and a button that is supposed to refresh the parent window on click.

<form>
<INPUT TYPE="button" NAME="myButton" onclick="handleOnClose();" value="press to close"/>
</form>

 //the js function
function handleOnClose() 
 {
    alert(window.parent.location); // this gives child window location instead
   window.parent.location.reload();  //refreshes child not parent  
//  window.top.location.reload();

// all the functions bellow didnt work.
 //  window.opener.location.reload(true);
  // window.opener.location.reload(false);   
   //  opener.location.reload();
   //  opener.reload();
    // window.opener.location.reload();
    // document.opener.document.location.href = document.opener.document.location.href;

 }

I also tried to trigger on window close event to call the parent window refresh but I had problems with chrome and the child window being refreshed instead of parent.

<script> window.onBeforeUnload=handleOnClose();</script>

Solution

  • The problem was because the development mode was enabled on my account. If you have it enabled and you find something weird going on, disable it and try again. There's some issues with dev mode right now.