enter image description hereI am trying to add some JavaScript/ Style inside HTML rich text editor field in SharePoint 2013, as we can add in the content editor but it strips all script tags.

I tried embedding script inside HTML rich text editor field but it is not working and it also visible as normal text in a browser.

We have an HTML rich text editor field where we add description text which can have some anchor tags, we want to add a javascript function on onclick event in the anchor tag. We don't want to add any function to Page Layout/ Master Page. Neither wants to add a link to any JavaScript files, as we have lots of pages and calling the function by id will not be a good solution. Please advise.

  • What about using the jslink property on the site column? – Anders Aune Jul 13 '16 at 10:40

You can use embed code in rich HTML text editor:

enter image description here

After clicking the command, you are prompted to insert your code and given a preview:

enter image description here

Alternative solution:

SharePoint creates a Script Editor webpart on the page for you. It even includes an "Edit Snippet" button, so you can go back and edit the code later.

enter image description here

OR you can use Content editor webpart and add your JS file as a source in Content Link.

You will get more info from here.

|improve this answer|||||
  • 1
    I tried embedding code but it is not working. JavaScript code appears as normal text in browser . When i adding <script></script> tags it stripping all these html part. – Shivendra Patel Jul 13 '16 at 7:33
  • You need to add it within html content. Just as defined in the link I've provided in the answer. You need to attach jquery library references before using it otherwise it will give you '$ undefined error'. – Dikesh Gandhi Jul 13 '16 at 7:41
  • You can use script editor/ content editor webpart as an alternate solution. – Dikesh Gandhi Jul 13 '16 at 7:41
  • Doesn't work for me as well. It seems that the solution is related to a web part, but not to a Rich text field. – MikhailSP May 31 '17 at 12:00

You could also upload your own html file, create a content-editor-webpart and link to the html file in the text file property of the content-editor-webpart. From here you can make changes to the html file with Sharepoint Designer

|improve this answer|||||

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.