You need to sign in to do that
Don't have an account?
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
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
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
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.
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.
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