javascript

A lot of people over the net ask the same question about detecting an internet connection state using javascript. This one is from ASP.NET forums. How to find out if the Internet connection is connected or disconnected in ASP.NET?

But ASP.NET runs on the server, so if the user’s Internet connection is disconnected, then the browser will not be able to connect to the webserver to run ASP.NET code, that’s why I thought this code should be client-side, so I dug a little in java-script and here is an example of what I found out:

<script language="javascript">function CheckOnline()
{
if(navigator.onLine)
      alert("You're online");
else
      alert("You're offline");
}
</script>
<body onload ="CheckOnline()">
</body>

I test it on Internet Explorer 7 and Mozilla and it worked well.