ukug_w
Last Updated: February 25, 2016
·
492
· philfreo

Listen for changes in internet connectivity

In our Backbone.js app for Close.io I wanted to show a red bar when your internet connection is gone.

// Listen for changes in internet connectivity
(function() {
    var errorView = null;
    $(window).on('online', function() {
        if (errorView) errorView.remove();
        errorView = null;
    });
    $(window).on('offline', function() {
        errorView = new ErrorView({ message: 'No internet connection.'});
        errorView.render();
    });
}());