Tuesday, March 23, 2010

Javascript errors - Object Expected, '_spBodyOnLoadFunctionNames', Expected ';' init.js

Another day of Sharepoint, another error.  I'm REALLY looking forward to upgrading to 2010.  Even if I have to rebuild these sites from scratch it will be worth it, because we have so much archaic code in our site that it could crash at any time and no one would know why (I've been here 6 months and all the consultants that used to work here quit/were fired/ran out of money).

Well these error have been plaguing the site intermittently for months. The first symptoms were being unable to click the site actions button (well you could click it but nothing would pop up except a javascript error), and missing site images/silverlight which would come up as red X's or just be missing completely.  Sounds like permissions, I know, but it wasn't in this case.  By the time I put a few hours in trying to diagnose this, it would "work itself out".  Also, while some people were having the problem, other could use the site fine.

And even better: the site works fine in Firefox!

Mystifying I know.  The first fix I implemented was adding this

<script type="text/javascript" language="javascript" src="/_layouts/1033/core.js?rev=CNBZRdV1h3pKuA7LsMXf3w%3D%3D;"></script>

<script type="text/javascript" language="javascript" src="/_layouts/1033/init.js?rev=VhAxGc3rkK79RM90tibDzw%3D%3D;"></script>

<script type="text/javascript" language="javascript" src="/_layouts/1033/ie55up.js?rev=VhAxGc3rkK79RM90tibDzw%3D%3D;"></script>


core.js was being added through a Sharepoint include, but the others weren't although they appeared in the source HTML. But strangely enough after adding those to the head tag, the errors cleared up.  Note the semi colon at the end of the source. That is needed.  I'm not sure why, but it is.

Then, of course, my application pages were working so I needed to add that the to application.master as well.  But it didn't work at first. Hmmm.... well turns out they were unghosted on the server so I had to go in into 12/Layouts/Templates and modify them on each WFE. Cool!  But still another error.  Oh wait, we used jquery for something (god knows what), and that was missing from the app.master so better add that as well.  Strange though that sharepoint only complained about it every month or so, for maybe 1/100 users. So I added to each WFE app.master:

<script src="/_scripts/jquery-1.3.1.js" type="text/javascript"></script>


Now the last errors to fix: _spBodyOnLoadFunctionNames.push('enableFlyoutsAfterDelay'); and '_spBodyOnLoadFunctionNames' is undefined.  The former caused by the latter.  To fix this I found a link to this article which I used method 2 to set things right. http://support.microsoft.com/kb/931509

Everything appears to be working now!!!  I'm kind of relieved but at the same time I'm worried it will come back (as it has before).  I'll be sure to update if it rears its ugly head once again.