Skip to Content

networkAvailable()

Check (or set) the network availability (online/offline).

JavaScript July 2, 2019

Usage

JavaScript
nebula.networkAvailable(onload)

Parameters

onload
(Optional) (Boolean) True when this function is called on window load, use false otherwise
Default: None

Request or provide clarification »

Additional Notes

This function will add a body class of “offline” when the network is unavailable (and remove it when the network connection returns).

It is also called automatically when the network availability changes using the JavaScript events online and offline.

Source File

Located in /assets/js/nebula.js on line 414.

JavaScript
nebula.networkAvailable = function(){
    if ( navigator.onLine ){
        nebula.dom.body.removeClass('offline');

        if ( 'localStorage' in window ){
            localStorage.setItem('network_connection', 'online');
        }
    } else {
        nebula.dom.body.addClass('offline');

        if ( 'localStorage' in window ){
            localStorage.setItem('network_connection', 'offline');
        }
    }

    nebula.dom.document.trigger('nebula_network_change');
};

Override

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

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