Skip to main content

Cloud

JavaScript Duplicating Generated HTML in a Content Editor

Say you’ve become the office expert on food trucks. There are a lot of hungry people in your office, and you just don’t have time to keep them all updated on mobile meatballs. Why not add a Twitter list widget to your intranet site so they can track the trucks themselves?

The Content Editor web part sounds like the perfect place to insert the code that Twitter generates for you. So, you add a web part to your page, open the HTML source editor, and paste in the widget script. You’ll get a warning message, but let’s ignore that for now:

Warning: The HTML source you entered might have been modified.

Everything looks great, but let’s clean it up a little.

contentEditor

Obviously, you’ll want to get rid of that Content Editor title above the widget by changing the chrome type to none, but as soon as you do, the widget duplicates itself:

duplicates

As it turns out, SharePoint 2010 made some changes to the way the content editor handles JavaScript in order to combat cross-site scripting. Rather than being generated on the fly, the HTML is created and saved in the source each time the web part is updated. To prevent this problem, simply upload your script to a document library and point to it in the content editor’s content link setting.

link

The widget will stop duplicating itself, SharePoint will stop warning you about your HTML source, and you can get back to enjoying delicious, spaceship-delivered tamales.

Thoughts on “JavaScript Duplicating Generated HTML in a Content Editor”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

PointBridge Blogs

More from this Author

Follow Us
TwitterLinkedinFacebookYoutubeInstagram