_spbodyonloadfunctionnames is undefined Javascript Error in sharepoint

_spBodyOnLoadFunctionNames: Generally, ASP.NET 2.0 Master page concept is used for sharepoint pages and the “body ” is defined in master page. So, the content page is not able to add function to the body’s onload event directly. In order to work around this limitation, SharePoint provides the “_spBodyOnLoadFunctionNames” array. When the body is loaded, the onload event handler executes each function whose name is contained in this array. We added “myFunction” to the array so that it would run when the body’s onload event fires.
_spBodyOnLoadFunctionNames.push("myFunction ");

To fix the javascript error: View source of sharepoint page from browser.
1. Make sure in the head tag, init.js is included.

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

2. Body onload is properly defined.

<BODY scroll="yes" onload="javascript:if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();">

If these are not defined then it causes javascript error.
Hope, It helps.

No comments:

Post a Comment