Click to See Complete Forum and Search --> : internet connection


vinsa
09-08-2003, 03:36 PM
Hello, first sorry for my English.
I need for javascript for my webpage.
I use my page on my local computer
and want when onload the page, the
script to give me massage whether I have
internet connection or I havn't. Is this possible with
javascript?
Thank you in advance:)

pyro
09-08-2003, 05:16 PM
You can use something like this, which was designed to tell you whether your server is online or not, but will work well for this as well:

<script type="text/javascript">

var img = new Image();
img.src = 'http://www.somedomain.com/images/someimage.gif'; //point this to the location of an image file.
img.onload = function () {document.getElementById("online").style.backgroundColor="#00ff00";}
img.onerror = function () {document.getElementById("online").style.backgroundColor="red";}

</script>

Server Status: <span id="online" style="width: 10px; height: 10px; background-color: transparent; font-size: 1px;"></span>