tags:

views:

515

answers:

1

Possible Duplicate:
JavaScript: How to detect that the internet connection is offline?

How to check the internet is connected or not in javascript.

A: 

You can try to access a web page in Ajax every selected period of time. This code will help you:

http://www.codeproject.com/KB/scripting/InternetConnectionTest.aspx

It is very useful, and because it is Ajax based, is asyncronous, so you can check if the Internet is conected without leaving the original page.

For your convenience try to access a very fast page from a site that is always online (i.e. Google)

backslash17
You can't access sites outside of your domain (i.e. Google) with Ajax because of Javascript's same origin policy.
jimyi
You're right ,sorry! I forgot the javascript policy
backslash17
But the script works anyway, because at the end you want to know if the user has or not access to the pages you want to serve. Is not relevant if the problem is in the connection or the server, the fact is that there is or not access.
backslash17