SharePoint JavaScript – Page Load Add function: _spBodyOnLoadFunctionNames
In most cases SharePoint pages are based on a master page that contains the “body” element. These content pages can’t directly add a function to the body’s onload event. 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 “FunctionName” to the array so that it would run when the body’s onload event fires.
<script language="javascript">
_spBodyOnLoadFunctionNames.push("FunctionName");
function FunctionName()
{
// Code
}
</script>
Comments
Anonymous
June 22, 2009
PingBack from http://stevepietrek.com/2009/06/22/links-6222009/Anonymous
September 29, 2011
Usually you would want to declare the function executed before the call.Anonymous
June 27, 2012
What about passing parameters into function?Anonymous
October 16, 2012
@Alex, you can do it like this: _spBodyOnLoadFunctionNames.push("DummyFunction"); function DummyFunction() { OriginalFunction(param1, param2); }