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
AlaaAlaa 

encoding the URL in src atrribute when using the apex:iframe tag

Hi, am writing a visualforce page and using the <apex:iframe> tag the src attribute .. I need to encode the URL am passing in the src ..how can I do so?

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

The URLENCODE function should do the trick.  

 

Something like:

 

 

<apex:iframe src="/apex/AccountEdit?params={!URLENCODE(params)}"/>

 

 

All Answers

bob_buzzardbob_buzzard

I'm not quite sure what you mean by encode the URL, but you can use merge fields/formula in the src attribute, eg.

 

 

<apex:iframe src="/apex/AccountEdit?id=!{Account.id}"/>

 

 

AlaaAlaa

yes I know this so suppose in your example that the value of  Account.id contains some special character like "&" then the whole url will be wrong ... this is exactly what am facing now... am sending some parameter in the url and it does contain the "&" character so when I recieve it will be broken into two paramters... any idea?

bob_buzzardbob_buzzard

The URLENCODE function should do the trick.  

 

Something like:

 

 

<apex:iframe src="/apex/AccountEdit?params={!URLENCODE(params)}"/>

 

 

This was selected as the best answer
AlaaAlaa

Thats it .. thank you.

tggagnetggagne

But what if the text I want to encode is actual text and not a variable?

 

For example, 

 

a href="mailto:user@company.com?subject={!urlencode(resource plan for ){!somevariable}&body={!urlencode(thebody)}"

 

Must the user enter resource%20plan%20for%20{!somevariable} ???