network-connection

How to detect online/offline event cross-browser?

时间秒杀一切 提交于 2019-11-26 01:08:07
I'm trying to accurately detect when the browser goes offline, using the HTML5 online and offline events. Here's my code: <script> // FIREFOX $(window).bind("online", applicationBackOnline); $(window).bind("offline", applicationOffline); //IE window.onload = function() { document.body.ononline = IeConnectionEvent; document.body.onoffline = IeConnectionEvent; } </script> It works fine when I just hit "Work offline" on either Firefox or IE, but it's kind of randomly working when I actually unplug the wire. What's the best way to detect this change? I'd like to avoid repeating ajax calls with

How to detect online/offline event cross-browser?

让人想犯罪 __ 提交于 2019-11-26 00:58:52
问题 I\'m trying to accurately detect when the browser goes offline, using the HTML5 online and offline events. Here\'s my code: <script> // FIREFOX $(window).bind(\"online\", applicationBackOnline); $(window).bind(\"offline\", applicationOffline); //IE window.onload = function() { document.body.ononline = IeConnectionEvent; document.body.onoffline = IeConnectionEvent; } </script> It works fine when I just hit \"Work offline\" on either Firefox or IE, but it\'s kind of randomly working when I