Check if connected to a network; jQuery

后端 未结 7 1013
执笔经年
执笔经年 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:23

    You can either check the navigator.onLine property or listen to the offline/online events:

    $(document).on('offline online', function (event) {
        alert('You are ' + event.type + '!');
    });
    

    Source: http://www.html5rocks.com/en/mobile/workingoffthegrid/

    And here are some MDN docs for these events: https://developer.mozilla.org/en/Online_and_offline_events

    I'm not familiar with these events myself, but if you read the above links, you should find a lot of good information.

提交回复
热议问题