0

In Salesforce Knowledge articles, I'm trying to push data in Salesforce. (after refering this - https://goo.gl/U4kFHW)

I have the HTML file and it has few JavaScript function in it. I wasn't sure about this. For a test purpose, I added small JavaScript code in the HTML file and uploaded the zip.

<p id="demo"></p>

<script>
var cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML = cars[0];
</script>

This resulted as blank in the articles when it was published.

Any workaround to include JS function to work inside the Text (rich)? This will help in Salesforce Knowledge articles and else where too. Thank you.

2
  • Eww... W3Schools. One reason that snippet may not have worked in Salesforce is because you haven't waited for the DOM to initialise. Meaning when that Script is called, "demo" doesn't exist. Best adding. Refer to this but you'd want to put that script in a function and call it using something like document.onload or window.onload. You could try that first?
    – Dan Jones
    Commented Mar 8, 2016 at 10:08
  • Rich text may not support the JS code.
    – Viraj
    Commented Apr 15, 2016 at 10:12

1 Answer 1

3

No, you can't include JS code in Rich Text Fields. The whole purpose of this field type is to strip out active content such as Javascript. Part of the contract of the Rich Text Field type is that it consists only of markup, which is why you can safely render these fields unescaped without worrying about stored cross site scripting vulnerabilities.

If you want to store Javascript code in the Salesforce platform, the appropriate storage mechanism is static resources or in the body of your Visualforce page or Lightning renderer, controller, or helper files.

Please don't confuse code with data. sObjects and custom settings store data, not code. App data is stored in pages, static resources, components, or classes. Your app needs to respect this separation, as access rights to load data into the platform are very different from the AuthorApex perm necessary to load code into the platform. Users can load contents of objects, but only admins or privileged users can load code.

You must log in to answer this question.

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