Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for existance of an image 1

Status
Not open for further replies.

dle46163

IS-IT--Management
Jul 9, 2004
81
US
Hi!

I'm messing with the following code:

function check(){
var connect_img=new Image();
connect_img.onload=good_connect;
connect_img.onerror=bad_connect;
connect_img.src=" }

checkconnect=setInterval('check()',10000);

For the lines:
connect_img.onload=good_connect;
connect_img.onerror=bad_connect;

good_connect and bad_connect are functions that simply kick back a javascript alert.

While I'm testing for the existance of an image I'm actually testing to see if an internet connection is up and running...Everything works like it should when I first launch the script. However, if I unplug the ethernet cable to my pc while the script runs, the alert state doesn't change like I think it should. I thought defining the variable connect_img each time the function is called would do the trick but maybe I'm just not doing it right. Any thoughts would be great!

-dle
 
[tt]function check(){
var connect_img=new Image();
connect_img.onload=good_connect;
connect_img.onerror=bad_connect;
[blue]//one form of solution
var surl=" var sfx=(/\?/.test(surl))?"&":"?";
connect_img.src=surl+sfx+(new Date()).getTime();[/blue]
}[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top