SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question

migrated from Mar 14 '12 at 12:17

This question came from our site for professional and enthusiast programmers.

This would be better asked on SharePoint – Kyle Trauberman Mar 14 '12 at 2:36
Are you editing the content editor webpart with the rich text editor, or the page itself? – Kyle Trauberman Mar 14 '12 at 2:36
Just the content editor webpart. – mitch Mar 14 '12 at 2:50
up vote 0 down vote accepted

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.

share|improve this answer
perfect..thanks very much – mitch Mar 14 '12 at 4:01

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.