Detect the Internet connection is offline?

后端 未结 19 1384
甜味超标
甜味超标 2020-11-22 00:53

How to detect the Internet connection is offline in JavaScript?

19条回答
  •  渐次进展
    2020-11-22 01:33

    Here is a snippet of a helper utility I have. This is namespaced javascript:

    network: function() {
        var state = navigator.onLine ? "online" : "offline";
        return state;
    }
    

    You should use this with method detection else fire off an 'alternative' way of doing this. The time is fast approaching when this will be all that is needed. The other methods are hacks.

提交回复
热议问题