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

I'm having issues using the content editor web part on publishing pages of a SharePoint 2010 site. I paste the following JavaScript into a CEWP:

<script>
$(document).ready(function () {
        /* Show the column headers for the views of
           the list named in the tables' summary attributes.
        */
  $("table[summary*='Move list']").each(function(){ 
    $(this).find("tr:eq(0)").show(); 
  }); 

  });
</script>

And it mangles it to this:

<script>
$(document).ready(function () {
        /* Show the column headers for the views of
           the list named in the tables' summary attributes.
        */
  $("table[summary*='Move list']").each(function(){
    $(this).find("t(0)").show();
  });
});
</script>

Notice the .find() has been changed. This is one of the less dramatic mangling done by the CEWP; I've had it rip entire chunks out of the code block.

Anyone know what causes this? Very annoying, and this happens with style tags too.

share|improve this question
    
Why don't you use an HTML Forms Webpart instead? –  Daniel Ziga Oct 19 '11 at 9:10
add comment

1 Answer 1

up vote 2 down vote accepted

From what i can gather, seems like the CEWP has undergone some "improvement" in its 2010 incarnation.

One of this "improvement" is that the web part now perform some sort of "screening" on the html source code that a developer may try to insert, often resulting in invalid code without (almost) no warning.

Don't know if you are affect by the same issue, but this other question dig some more in the issue, providing some alterative solution. As a reference you could:

  • Use the HTML Form web part as Ziga suggested in his comment - this should solve the issue because the code won't be post processed
  • Use the Content Link property of the Content Editor web part to link an external script file (see this blog, you basically define a text file in a document library and then link that file from the web part)

Is an option for you to adopt one of this "workaround"?

share|improve this answer
    
Thanks, SPArchaeologist. Those two options are great. Also, for the heck of it, I tried the same CEWP with JS code on Firefox and IE. It works better (not perfectly) on IE. So I'll use IE and try those solutions. Thanks again :) –  Alex C Oct 19 '11 at 14:24
1  
Now THAT is strange. You mean that the same CEWP "fixes for you and outputs" a different javascript based on the browser you are using?? Very strange indeed, can only presume that the "fixing javascript" code performs some logic based on the browser vendor O_o ?? –  SPArchaeologist Oct 19 '11 at 14:42
    
I know. It could be on that one occasion, IE decided to not mangle the JS. Next time, it might do it. Seen stranger things from SP :) –  Alex C Oct 19 '11 at 18:34
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.