Skip to content

Run Javascript on Page Load

There are 2 options here. Which one to use depends on what you are trying to do. I tent to use option 1 as a default, and only switch to option 2 if I need to have my code run on every postback (ex: modifying a control on the page that changes on postback)

If you need to interact with an Obsidian control, neither of these options will work. You will have to use a mutation observer instead.

Option 1 - jQuery

This will execute once the page has finished loading. It will not run on postbacks.

$(function(){
    // Do some stuff
});

Option 2 - ASP.Net Load Hook

This will execute once the page has finished loading. It will also run on postbacks.

Sys.Application.add_load(function () {
    // Do some stuff
});