Here is how to check if web page is connected in JavaScript: http://www.kirupa.com/html5/check_if_internet_connection_exists_in_javascript.htm. This is well explained and you should take a look.
function doesConnectionExist()
{
var xhr = new XMLHttpRequest();
var file = "http://www.yoursite.com/somefile.png";
var randomNum = Math.round(Math.random() * 10000);
xhr.open('HEAD', file + "?rand=" + randomNum, false);
try
{
hr.send();
if (xhr.status >= 200 && xhr.status < 304)
{
return true;
}
else
{
return false;
location.reload();
}
}
catch (e)
{
return false;
}
}