This may be an easy one.

When I add javascript code and HTML to a Sharepoint 2007 content webpart, if I then go in and edit the page using the rich text editor and save, the javascript disappears.

Is their a wrapper or something similar I can use to retain the javascript after a user has used the rich text editor.

Appreciate any help.


  • This would be better asked on SharePoint Commented Mar 14, 2012 at 2:36
  • Are you editing the content editor webpart with the rich text editor, or the page itself? Commented Mar 14, 2012 at 2:36
  • Just the content editor webpart.
    – mitch
    Commented Mar 14, 2012 at 2:50

2 Answers 2


Since you are including the script tag in the content editor web part, then editing the webpart with the rich text editor, the RTE is encoding the script tags, causing them to not execute.

You can fix this by placing a second content editor web part on the page above the one you are editing that contains nothing but the script tag.


In environments where publishing is enabled, and in SharePoint 2010 CEWP's, you may also run into the issue that when you edit the web part, the script has already run so the content generated by the script has already been added to the web part as source markup. This results in multiple copies of your content being generated and saved every time you edit the page.

For scripts, I prefer the approach of creating a Document Library called "Scripts", and storing my scripts there; then point your CEWP to the applicable JS file in the library. This also promotes/allows reuse of those scripts across multiple pages in the environment as opposed to manually duplicating them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.