2

I have some script to denormalize the tags that get normalized in the Ajax return. The problem is that when I do: str.replace( /&/g, "&" ) in my script, the VisualForce page rendering alters the string to be: str.replace( /&/g, "&" ). It's not at all the same thing. Is there a way to keep the VisualForce page rendering from altering my script when it translates the page?

This may be the answer, I probably should change it to a resource and just add a reference to the separate script file. The trouble with this is that changing a debugging the script will be painful because I'll have to keep reloading the resource every time I make a change. I was planning on doing this later but during the development phase, this will be painful.

  • It's not clear from your posting what the different is, both str.replace calls look identical. Typo? – Ralph Callaway Jul 19 '13 at 16:09
  • Stack Exchanged rendered both the & and & as & in the original question because they weren't included in in-line code marks (`). – Matt K Jul 19 '13 at 16:37
  • Looks like I should have enclosed the post in code tags because it has been normalized to the point the code has been removed. I put the script and style sheets in a resource within my org but now the Ajax code is broken and I'm not sure why. All I did is remove my javascript from the page and place it in a resource. Now when I try to invoke the remote method, the VF Ajax handler fails with the exception of "b is undefined". – Robert Harper Jul 19 '13 at 16:46
2

You'll want to use this insead:

str.replace( /{!HTMLENCODE('&')}/g, '&' );

The HTMLENCODE visualforce function will encode the ampersand (&) into & on the server-side when the page is loaded.

In the page source, it will appear as:

str.replace( /&/g, '&' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.