Check if connected to a network; jQuery

后端 未结 7 1015
执笔经年
执笔经年 2020-12-13 20:37

I have searched through StackOverflow and have seen various topics on how to do this, but nothing that really pertains to my particular situation. I am writing (for a class)

相关标签:
7条回答
  • 2020-12-13 21:28

    I'm using the following code to check for connectivity. NOTE: none of the solutions above work for Firefox, which relies on its internal 'Work Offline' status:

    // Register listeners
    window.addEventListener("offline", function(){
        $('#globalDiv').hide();
        $("#message").html('WARNING: Internet connection has been lost.').show();
    });
    window.addEventListener("online", function(){
        $("#message").empty().hide();
        $('#globalDiv').show();
    });
    
    0 讨论(0)
提交回复
热议问题