You need to sign in to do that
Don't have an account?
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 = '<table>';
for(var i=0; i < objCollection.length; i++){
dhtml += '<div>' + objCollection[i].someProperty + '</div>';
}
dhtml += '</table>';
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
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?
My blog has some articles on how I'm encoding JS/JSON in Visualforce
http://www.embracingthecloud.com/2009/11/05/GivingVisualforceASPATreatmentPart1.aspx
http://www.embracingthecloud.com/2009/11/07/GivingVisualforceASPATreatmentPart2.aspx
Hope this helps!
-Mike