May 9, 2011

Invalid HTML in CEWP Causes Javascript Error on Page

One of my customers had a problem with the webpart menu on certain site pages in MOSS 2007 with a Content Editor Webpart on the page. The webpart menu on the content editor webpart and randomly, it seemed, on some other webparts on the page, wouldn't open at all and the page reported an error. Debugging this, the error I got was 'style.display' is null or not an object in the javascript file ie55up.js.

This error message, however, isn't really helpful for correcting the problem. There is nothing wrong with the javascript code, nor the webpart menu; the problem is the html in the content editor webpart contents. Apparently the editor of the page had copy-pasted the contents of the webpart from one to another and yet another, resulting in unwanted div-tags in the beginning of the webpart content, containing a false id attribute which seems to cause the javascript error.

So, to correct this error one should get the content editor webpart to editing mode, open the rich text editor and there swich to the html code view with the < > -button and delete these div-tags. Not an easy task though, when this very thing is causing an error opening the webpart menu! On one site, I managed to get the menu to work again by closing the webpart and then adding it to the page again from the closed webparts gallery. But on the other sites, trying to close the webpart only ended up in a SharePoint error page.

So what I did, was to open the page content list by adding ?contents=1 on the address bar after the page url and delete the whole webpart on that page. There it didn't cause an error. After that I could add a new content editor webpart on the page, without errors. And since I still wanted to restore the old contents, I had copy-pasted it form the page to notepad, from which I could then again copy-paste it to the new CEWP, clean.

1 comment:

Anonymous said...

I cant thank you enough. This problem cropped up today for a couple users and I found your post.