There are two page events that fire when a page loads. You can add script to the event handler for either.

Event NameOccurs When
OnPageLoadStartedA page starts to load, and immediately before the controls on the page are loaded (i.e., the pre-load script). At this point, it is not safe to reference elements on the page.
OnPageLoadCompleteAll other page setup has completed (i.e., the post-load script). At this point, page elements can be safely referenced and initialized or manipulated.

It is common to use these script event handlers to create custom script functions and to initialize global variables.

Page event handlers have access to intrinsic objects: Page and EventName.

Page event handlers can be edited using Property Explorer.

For an example of how to use the OnPageLoadComplete event to create a custom script function, see Script Context.