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

前端 未结 10 1711
你的背包
你的背包 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:36

    My solution is to grab a very small image (1x1), not cached and always onLine.

    
    
    
    
    
    
    

    Notes:

    • Use a local copy of jQuery otherwise it won't work offLine.

    • I've tested the code onLine/offLine and it works without delay.

    • Works with all browsers, Desktop or Mobile.

    • In case you wonder, there's no tracking made from Google Analytics as we don't use any arguments.

    • Feel free to change the image, just make sure it doesn't get cached and it's small in size.

提交回复
热议问题