Trigger Javascript Function on SharePoint Page Load

Want to trigger a Javascript function on SharePoint page load? All you have to do is push your function’s name to this array and it will trigger in the OnLoad event of the window.

Example: Place this code in CEWP:

 _spBodyOnLoadFunctionNames.push("MyFunction");
 function MyFunction() {
     alert('it works');
 }

In custom SharePoint pages, this chunk needs to be added just below: PlaceHolderMain or PlaceHolderAdditionalPageHead

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply