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
Mike LeachMike Leach 

Javascript in VF Pages Corrupted By HTMLEncoding

This Javscript within a VF Page:

 

var dhtml = '<table>';

for(var i=0; i < objCollection.length; i++){

dhtml += '<div>' + objCollection[i].someProperty + '</div>';

}

dhtml += '</table>';

 

 Is being HTML encoded and rendered to the browser as:

 

var dhtml = '&lt;table&gt;';

for(var i=0; i &lt; objCollection.length; i++){

dhtml += '&lt;div&gt;' + objCollection[i].someProperty + '&lt;/div&gt;';

}

dhtml += '&lt;/table&gt;';

 

Does inline Javascript need to be wrapped in any particular apex control to disable HTML encoding? 

 

I noticed apex outputText values can be wrapped in encoding macros, but I prefer not to emit inline javascript from controller properties.

 

Thanks in advance for any guidance you may be able to provide!

 

-Mike 

Mike LeachMike Leach

Some things I've tried (and failed).

 

1) Upload content as static resource. This works, but requires re-uploading the file with every JS change.  Would like to make changes in Eclipse, save, and test.

 

2) Move script to Component. The script actually renders without encoding, but the component is wrapped in a <span>, which confuses the browser. 

 

3) Move script to separate Page and include as script src. Same issue as before.

 

The OutputText control has an escape attribute that can be set to false. Is there a page level equivalent that would allow inline script with encoding?

trishtrish
I'm having the same problem. Cubic Compass, were you able to fix this?
Mike LeachMike Leach