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
code redcode red 

Set iframe source from VF page

Hi,

 

We need to set the source of an iframe using a text field on a VF page on page load. The text field on the parent page contains the name of another VF page to load in the iframe.

 

This works (full URL):

<iframe width="100%" height="500" frameborder="0" scrolling="true" marginheight="0" marginwidth="0" src="https://c.na7.visual.force.com/apex/aaobarchartplain" ></iframe>

 

This does not (where Dashboard_Report__c is the custom object, and Page_Name__c is the name of the field containing the name of the VF page we want to load in the iframe; page name example is rmbarchart):

 <iframe width="100%" height="500" frameborder="0" scrolling="true" marginheight="0" marginwidth="0" src="Dashboard_Report__c. Page_Name__c"></iframe>

 

On the latter, an error is thrown; “The name 'c.Page_Name' can only contain alphanumeric characters, must begin with a letter, and must be unique.”

 

This also throws an error:

 <iframe width="100%" height="500" frameborder="0" scrolling="true" marginheight="0" marginwidth="0" src="Page_Name">

Error; “Page Page_Name does not exist”

 

Any help or suggestions is appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

You need to use an expression to get the value of that field substituted....

src="{!Dashboard_Report__c. Page_Name__c}"

 

(Or it probably needs to be

src="Dashboard_Report__r. Page_Name__c"  to follow the relationship

)

All Answers

RaviJprRaviJpr

HI

 

You should write something like this.

 

In Class:-

 

public string myPageName{get;set;}

 

public yourclassname(){

 myPageName = Dashboard_Report__c. Page_Name__c;

}

 

On Apex page:-

 

<iframe width="100%" height="500" frameborder="0" scrolling="true" marginheight="0" marginwidth="0" src="{!myPageName}"></iframe>

 

Thanks,

Ravi

aballardaballard

You need to use an expression to get the value of that field substituted....

src="{!Dashboard_Report__c. Page_Name__c}"

 

(Or it probably needs to be

src="Dashboard_Report__r. Page_Name__c"  to follow the relationship

)

This was selected as the best answer
code redcode red

Thank you aballard! That did it!

 

You need to use an expression to get the value of that field substituted....

src="{!Dashboard_Report__c. Page_Name__c}"

 

Extremely grateful for your help!

 

(Thank you too Ravi; I can use your suggestion elsewhere!)