I have a javascript method

$(document).ready(function() { pageViewed('{!currentName} - Detail Page');

Here currentName can have special characters like a single quote. Is there any way to skip the escape character? while passing it to the pageviewed method?

Is there any method that does this automatically?

  • 1
    probably wrap the entire {!currentName} in a double quote like var a = "{!currentName}", if you know a single quote is the only special character that would be coming in. If not use js methods like encodeURI() or encodeURIComponent() to escape the special chars. Now if you want to remove the chars then , we should be able to use regex to remove the chars.
    – Sumuga
    Commented Dec 29, 2017 at 8:57

1 Answer 1


Apart from JavaScript, Visualforce has functions to escape special characters.

You can use JSENCODE as:

pageViewed('{!JSENCODE(currentName)} - Detail Page');

Additional encoding methods: HTMLENCODE or JSINHTMLENCODE

  • That is exactly what I was looking for. Thanks a lot
    – Rimii
    Commented Dec 29, 2017 at 11:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .