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
RockersRockers 

How to render the HTML content on the VF Page

Hi Friends,

 

 I got one requirement to render the HTML Code on the VF Page where that HTML code is stored in object as a text.

 

For example, In the object, i entered the text like : "Simply <a href="www.google.com">click</a> here to connect to Google."

so, now when i retreive the data from that object, and display on the page, then it displays like as below:

"Simply <a href="www.google.com">click</a> here to connect to Google." as we entered the data in the object.

 

Now, my requirement is the above text should be displayed on the page like as below:

 

Simply click here to connect to Google. (just like HTML Code).

 

How to rendered the text as HTML Code on the page.

 

Please help me to solve this. Thanks in advance...........

 

Regards,

Phanikumar

Navatar_DbSupNavatar_DbSup

Hi,

 

Set contentType="html" attribute of the <apex:page> tag for display the output of the html stored as text. Before display the text you need to convert special symbols like <,>/ and others.

 

For example:

Dipslay=dipslay.replaceAll ('&lt;','<').replaceAll('&quot;','"').replaceAll('&gt;','>');

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

bob_buzzardbob_buzzard

Are you using apex:outputText to render the HTML? If so, try setting the escape attribute to 'false' - that is intended for this type of use case.

aballardaballard

If you use excape=false to render html, be aware it is up to you to ensure your page does not have any XSS security vulnerabilities.