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();
});
}());Written by Phil Freo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Internet
Authors
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
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#