Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

MitchK

share|improve this question

migrated from stackoverflow.com 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
add comment

2 Answers 2

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
add comment

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
add comment

Your Answer

 
discard

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