Last Updated: February 25, 2016
·
892
· 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();
    });
}());

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside