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
John VitalesJohn Vitales 

Update Visualforce page iframe's source from a different Apex component

Hello everyone,

I have a Custom Object that has an in-line Visualforce Page which is basically an iframe. The iframe's source is coming from the Custom Object's "selected source" field.

 

<apex:page standardController="Custom_Obj__c"  >
    <iframe src="{!Custom_Obj__c.Selected_source__c}"  />
</apex:page>

This is all in one "App".  This app also has an apex component that enables me to update the "Selected Source" field.  Although the record is updating correctly, the changes doesn't seem to reflect until I refresh the page.  This means the iframe doesn't update unless the page is refreshed.  I do not want the page to refresh and so the ideal solution is if I can have the apex component update the Visual Force page's iframe source directly rather than updating the Selected Source field first then refreshing the page.

I cannot seem to find a way to do this because the standardController on the Visualforce page has to point to the Custom Object otherwise I cannot use the iframe on my Custom Object.

Is there a way for my apex component to update the iframe's source directly? Or, is there a way to include an iFrame into a custom object without the use of Visualforce page?

Any help would be much appreciated.

 

pandu ranga 16pandu ranga 16
hi 

public with sharing class YourClass {
// Source var for the iFrame
public String iframeSource { get; set; }

// Constructor public YourClass() {
// Default value of the frame source iframeSource = 'apex/Page1';
}

// The method to reload the iframe with another source page public PageReference reloadIframe() {
iframeSource = 'apex/Page2'; return null; }


Now create a command button to reload the iFrame and the pannel to be refreshed:

<apex:commandButton action="{!reloadIframe}" reRender="theFrame"/>
<apex:outputPanel id="theFrame">
        <apex:iframe src="{!iframeSource}" />
</apex:outputPanel>