Wednesday, June 13, 2012

Content Editor Web Part duplicating content

Today I received a request mentioning that Content Editor Web Part is duplicating the content. The user was adding clock object prepared in Adobe Flash. This clock was being duplicated whenever the user is editing the web part.

I checked the content editor web part. It has got too many "<embed>" tag. The tags were being duplicated. The clock was being rendered using some JavaScript method. We inspected the method. The method was using "document.write" to add the "<embed>" tag.

Content editor web part renders its HTML/JavaScript content on its canvas. So document.write was adding "<embed>" tag on every "Save" for the web part. So every edit action for the web part was adding "<embed>" tag causing duplicate clocks (content).

We resolved the issue by creating separate content file for Content Editor Web Part. The content file is linked to the Content Editor Web part. As the "document.write" is moved to separate file, for every request the file is read and parsed for render. "document.write" do not append content in the file. So it has no duplication of content.

Always use separate content file whenever we have a content which includes "document.write" in JavaScript.

More Reference(s):

Post a Comment