Content Editor Web Part JavaScript Error

15 May

After installing SharePoint (MOSS) SP1, I ran into a problem with many of my Content Editor Web Parts (CEWP) wherein when you press ‘edit’ instead of showing the nice toolbar, you get a javascript error.

image

"Object does not support this property or method"  on line 169.

I debugged the javascript using Visual Studio, and it was immediately apparent that a string cast was needed in line 168 of assetpicker.js.

You can find this javascript file here:

Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS1033assetpicker.js

The area of code in question looks like this:

    <span class="kwrd">for</span>( <span class="kwrd">var</span> i <span class="kwrd">in</span> propArray )<br />    {<br />        <span class="kwrd">var</span> nameValuePair=propArray[i].split(<span class="str">&quot;=&quot;</span>);<br />        <span class="kwrd">if</span>(nameValuePair.length==2)<br />        {<br />            objectToPopulate[nameValuePair[0]]=decodeURIComponent(nameValuePair[1]);<br />        }<br />    }

The line in question is where the variable ‘nameValuePair’ is created, and assigned the value from propArray[i].split("=").  The members of propArray aren’t strings, and as such the split command isn’t available.

Change that one line to use a javascript string cast.  Which can be done by wrapping "String(…)" around the array.  (In red below)

    <span class="kwrd">for</span>( <span class="kwrd">var</span> i <span class="kwrd">in</span> propArray )<br />    {<br />        <span class="kwrd">var</span> nameValuePair=<font color="#ff0000">String(propArray[i]).split(<span class="str">&quot;=&quot;</span>);</font><br />        <span class="kwrd">if</span>(nameValuePair.length==2)<br />        {<br />            objectToPopulate[nameValuePair[0]]=decodeURIComponent(nameValuePair[1]);<br />        }<br />    }

That change is on line 168.  Try making it in the javascript, and clear your temporary internet files/browser cache, then revisit your SharePoint site.  The toolbar should show up now.

Tweet about this on TwitterShare on Google+Share on FacebookShare on RedditEmail this to someoneShare on LinkedInShare on StumbleUpon

Leave a Reply

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