How to check if the user is online using javascript or any library?

前端 未结 10 1737
你的背包
你的背包 2020-12-03 01:35

I need some help on how I could check the internet connection using Javascript or jQuery or any library if available. cause i\'m developing an offline appl

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 01:52

    i think you should try OFFLINE.js.. it looks pretty easy to use, just give it a try.

    it even provides the option checkOnLoad which checks the connection immediately on page load.

    Offline.check(): Check the current status of the connection.

    Offline.state: The current state of the connection 'up' or 'down'

    haven't tried it, would be nice to know if it works as intended.

    EDIT took a little peak into the code, it uses the method with FAILED XHR REQUEST suggested in THIS SO Question

提交回复
热议问题