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
NachoNacho 

getting escaped HTML

Hi

 

I'm trying to get the HTML code of a chart and assigning it to an atribute of the controller.

 

<apex:inputText value="{!chartHTML}" id="chartHtmlInput" style="display:none;"  />

 

I've got the atribute chartHTML specified in the controller and I'm trying to asign to it the HTML code of a chart.

 

so I use the following javscript code

 

document.getElementById('{!$Component.chartHtmlInput}').value= document.getElementById('{!$Component.chartPanel}').innerHTML;

 

sadly the HTML code I'm getting is escaped, as you know I can't use the attribute "escape" in <apex:inputText>

 

any Ideas how can I get my code non-escaped?

 

Thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
NachoNacho

Solution:

 

You have to escape the caracters in the following way

 

document.getElementById('{!$Component.chartHtmlInput}').value=  escape (document.getElementById('{!$Component.chartPanel}').innerHTML);

 

and then, in the controller you have to use the decoded text, you do the following

 

String decoded = EncodingUtil.urlDecode(chartHTML, 'UTF-8');        

 

That string contains the un-escaped HTML code and asings it to a String "decoded"

 

Thanks anyway

 

Cheers

All Answers

Ankit AroraAnkit Arora

Why you are using inputtext try using outputlabel with escape="false" as it will also return you the innerHTML in javascript. Is there any specific reason to use inputtext?

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

NachoNacho

I tried using outputLabel but when I run a System.debug(chartHtmlInput) I get "null" as a result.

 

I'm using an inputText because the Chart I'm trying to get changes dinamically, it's a Gantt Chart and you can chance the position of the different tasks, etc.

 

The idea is obtaining the HTML of that chart so I can send it through email as an attachment.

 

The problem is that the user is recieveing HTML code instead of a nice chart.

sjain1.2523113033806995E12sjain1.2523113033806995E12

Below is the sample code, it would help you.

 

<input type="hidden" value="{!Descrption}" id="hidden1"/>

<span id="p1">Description</span>

 

<script>
document.getElementById('p1').innerHTML = document.getElementById('hidden1').value;

</script>

 

You can manipulate your code according to the above sample code.

NachoNacho
This is what the program is currently doing, with no success whatsoever. I'm starting to doubt if there may be problems with the coded HTML
NachoNacho

Solution:

 

You have to escape the caracters in the following way

 

document.getElementById('{!$Component.chartHtmlInput}').value=  escape (document.getElementById('{!$Component.chartPanel}').innerHTML);

 

and then, in the controller you have to use the decoded text, you do the following

 

String decoded = EncodingUtil.urlDecode(chartHTML, 'UTF-8');        

 

That string contains the un-escaped HTML code and asings it to a String "decoded"

 

Thanks anyway

 

Cheers

This was selected as the best answer