Sunday 10 August 2014

Refreshing Parent Window of Inline Visualforce Page from Child Window Opened from Inline Visualforce Page

The problem statement is From Inline Visualforce We need to open a Child window and then from that child window we need to refresh the Parent window of the Child window or redirect Parent window of the child window .

Last night ,I was struggling on how to redirect the Parent Window from the child window that was opened from the Inline window 

I tried hard on how to solve this ,but finally last resort was to post the query on salesforce stackexchange .The below is the link for the same

The error was due to Javascript security of web browser .

I tried the below script on the child window


  function test(){


Unsafe JavaScript attempt to initiate navigation for frame with URL '' from frame with URL ''. The frame attempting navigation is neither same-origin with the target, nor is it the target's parent or opener.

The browser security features don't allow navigation from child window directly since visualforce and standard detail page are in different domain.The above error is due to the same feature .

Stackexchange has really expert professionals and Eric suggested me the below solution.I am posting the same so that helps others

The Inline page on the parent window has the below code

<apex:page standardController="Account" extensions="Accountctrl">
<apex:form >
  function openwindow(){"/apex/pagereal", "myWindow", "width=200, height=100");
  function navigate(){'';//Parent function that redirects
<apex:pageBlock >
 <apex:pageBlockSection columns="1" id="Test" >
  <apex:inputcheckbox value="{!test.istest__c}" label="Same as Above">
    <apex:actionSupport event="onchange" rerender="Test" />
<apex:outputPanel rendered="{!NOT(test.istest__c)}"> 
<apex:inputField value="{!test.Campaign__c}" />
<apex:inputField value="{!test.cust_vendor__c}" />

Note that navigate function we will call from the child window and that would navigate parent frame

<apex:page >
 <!-- Begin Default Content REMOVE THIS -->
 This is your new Page


 function test(){
     window.opener.navigate();//call the parent function from child window and that does the trick

  <apex:form >
 <!-- End Default Content REMOVE THIS -->
  <apex:commandButton onclick="test()" value="Test"/>
The child window script will call the opener  window script and that in turn will redirect the parent frame .

Hope this trick will be useful .

No comments:

Post a Comment

Introducing Lightning Base Components

Lightning Base Components are great addition to the platform and in fact revolutionary .One of the concerns around lightning component ...