Scenario
If you a have some javascript code that needs to be executed on the onLoad event of a page in SharePoint.
Solution
SharePoint provides a JavaScript array "_spBodyOnLoadFunctionNames", any function to be executed onLoad needs to be added to this array e.g.