Javascript (?) help - need to check connectivity

From: Monsoir (PILOTDAN) 3 Sep 2011 16:42
To: Peter (BOUGHTONP) 13 of 18
Think I've sussed the problem, maybe. I've added a "didError" variable and set it to one when the error occurs. However, because it's not triggering UNTIL the error, my code is going ahead and executing before the image has failed
From: Monsoir (PILOTDAN) 3 Sep 2011 16:52
To: Peter (BOUGHTONP) 14 of 18
code:
function checkImageUrl()
{
 
$('#ImageTest')
  .error(function() {
  setTimeout("checkImageUrl()", 2000);
  })
 
  $('#ImageTest').load(function() {
  window.location.replace(redirectURL);
  });
 
  $('#ImageTest').attr("src", imageURL + "?=" + d.getTime());
 
}
 
checkImageUrl();


Trial and error, yay!
From: Monsoir (PILOTDAN) 3 Sep 2011 16:55
To: Monsoir (PILOTDAN) 15 of 18
Hmm, this does work but looking at it in FireBug, it appears to exponentially load images and I'm not really sure why :(
From: Monsoir (PILOTDAN) 3 Sep 2011 17:06
To: Monsoir (PILOTDAN) 16 of 18
Ah, every time the function is called I'm creating a new event handler. Moved them out of the function and I think I'm there.
From: Peter (BOUGHTONP) 3 Sep 2011 17:14
To: Monsoir (PILOTDAN) 17 of 18
Yay!

Course once you switch to IE7 you'll probably find some random annoying error cropping up just to be a pain. :(
From: Monsoir (PILOTDAN) 3 Sep 2011 17:24
To: Peter (BOUGHTONP) 18 of 18

You were right :D Just does nothing after the first event in IE, I guess changing the image url doesn't force a reload of the image.

 

I have, however, got it working by forcing a page refresh. I'll try and figure out how to get IE to reload the image because it's much cleaner, but at least I can make it work regardless.