Using JS Remoting I want to generate HTML content in the backend and then display it in the VF page.
I am building the string in the controller as per follows:
String account = [SELECT Id, Name FROM Account LIMIT 1];
String htmlContent = 'This is the string built in APEX <a href="' + account.Id + '" target="_blank">Click here if you want to visit ' + account.Name + '</a>. This is an example';
Now, when I debug the string in Firebug onto the page, it comes encoded as per follows:
This is the string built in APEX <a href="' + account.Id + '" target="_blank">Click here if you want to visit ' + account.Name + '</a>. This is an example
Which is fine and I understand Salesforce does it for security reasons.
Before I jumped into the proper solution, which is passing the ID and the NAME only, and then build the string in JS, I though I'd give it a go with replacing the encoded string with JS functions. And I did so:
function getString(param1)
{
ClassName.Method(param1, function(result, event)
{
if(event.type === 'exception')
{
return false;
}
else if(result)
{
console.log(result.message.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'));
}
else
{
// do something....
}
});
}
In the console I still get the same result, < and > are not replaced with < and > accordingly.
Then I ran the same code in pure HTML + JS, and it works.
Next thing I tried was logging indexOf('<') and it returned -1. However, indexOf('lt;') and indexOf('&') both returned the correct position in the string.
Does anyone know WHY this doesn't work in VF?