0

I want to check if internet is available or not when the web page loads. I want to do this in order to:

  • disable like buttons request if offline, during development
  • load local links if no network, otherwise load from HTTP
  • call more data from server in appcache based offline apps only if user is online

How do I achieve this?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Shubham Badal
  • 1,125
  • 13
  • 33
  • http://stackoverflow.com/questions/189430/javascript-how-to-detect-that-the-internet-connection-is-offline got alot of examples for the offline checking question. – Avi L Nov 16 '14 at 15:26

1 Answers1

1

The window.navigator object has an online property that you can use:

https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine.onLine

Alternatively you can make a quick Ajax request and check the error code you receive.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52