Skip to Content
Menu

bufferedWindowLoad()

Run a function at window load, or if the window has already loaded run it immediately.

JavaScript April 4, 2021

Usage

JavaScript
nebula.bufferedWindowLoad(callback)

Parameters

callback
(Required) (Function) The function to run at window load
Default: None

Request or provide clarification »

Examples

JavaScript
nebula.bufferedWindowLoad(function(){
    //Do something at window load
});

Useful for inside dynamic imports that happen on DOM Ready and need a window load listener inside of them; the window load may happen before the import finished loading.

JavaScript
jQuery(function(){
    import('./modules/whatever.js').then(function(module){
        nebula.bufferedWindowLoad(function(){ //This may actually happen inside of the module file itself, but for demonstration purposes doing it all here 
            //Do something at window load
        });
    });
});
Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /assets/js/modules/utilities.js on line 5.

    No Hooks

    This function does not have any filters or actions available. Request one?
    JavaScript
    nebula.bufferedWindowLoad = function(callback){
        //If the window load event has already happened, run the callback immediately
        if ( document.readyState === 'complete' ){ //Note: "interactive" = DOM Ready, "complete" = Window Load
            return callback();
        }
    
        //If the window has not yet loaded, add an event listener to wait for it
        window.addEventListener('load', function(){
            return callback();
        });
    };
    

    Override

    To override or disable this JavaScript function, simply redeclare it with the exact same function name.

    JavaScript
    nebula.bufferedWindowLoad = function(callback){
        //Write your own code here, leave it blank, or return false.
    }