I'm using the below script to check for internet connection by downloading the image test.png. The issue I'm having is that it will only download the image once. This means, if there was internet connection when the page was first loaded it will display "Online" - however, if I disconnect the network cable, it won't say "Offline", as it should.
Basically, once downloaded, the readyState
will always be 'complete
' - However, I would like to perform the test again and again.
<script type="text/javascript">
setInterval('checkimage()', 1000);
function checkimage() {
var imgTmp = new Image();
imgTmp.src = 'test.png';
if (imgTmp.readyState == 'complete') {
document.getElementById('div1').innerHTML = "<font size=15 face=ariel color=green>Online</font>";
} else {
document.getElementById('div1').innerHTML = "<font size=15 face=ariel color=red>Offline</font>";
}
}
</script>
Any help would be greatly appreciated!