2

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.

1
  • Why don't you use an HTML Forms Webpart instead?
    – user2536
    Oct 19, 2011 at 9:10

1 Answer 1

2

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"?

3
  • 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, 2011 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 ??
    – SPArcheon
    Oct 19, 2011 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, 2011 at 18:34

Your Answer

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

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