标签云

微信群

扫码加入我们

WeChat QR Code


This is a way to detect that a connection to the server failed, not that the browser is offline. If that's good enough for you, most libraries have a way to set a handler for all failed Ajax requests. However, navigator.online is the property that tells you that you are connected to the internet.

2018年09月27日42分21秒

window.navigator.onLine only tells if the browser is set to offline -mode (at least in Firefox). If the Internet connection has been lost, it will still show true, for me at least.

2018年09月26日42分21秒

navigator.onLine works well in Chrome (5 years later). I would recommend using that unless you have a very specific scenario.

2018年09月26日42分21秒