var ConnAttempts = 0 var $j = jQuery.noConflict() $j(document).ready(init) function init() { $j('body').append('<div id="status-msg"></div>') checkConnectivity() } function checkConnectivity() { $j('#status-msg').text('Trying to connect...') ConnAttempts++ var TargetUrl = 'http://whatever' $j.get( TargetUrl , handleUrlResponse ) function handleUrlResponse(data,status) { if (status == 200) { // Hooray! Lets go redirect location.href = TargetUrl } else { // Boo! Still not ready if ( ConnAttempts > MaxConnAttempts ) { $j('#status-msg').text('Received status '+status+' after '+ConnAttempts+' tries.') } else { $j('#status-msg').text('Please wait...') setTimeout( checkConnectivity , 300 ) // 0.3 seconds } } } }
<img alt="Connecting..." id="ImageTest" /> <script type="text/javascript"> $('#ImageTest') .error(function() { alert('Handler for .error() called.') }) .attr("src", $imageURL); </script>
function setImageUrl() { $('#ImageTest') .error(function() { alert('Handler for .error() called.') setTimeout( setImageUrl , 300 ) }) .attr("src", $imageURL); } setImageUrl()
function checkImageUrl() { $('#ImageTest') .error(function() { setTimeout("checkImageUrl()", 2000); }) $('#ImageTest').load(function() { window.location.replace(redirectURL); }); $('#ImageTest').attr("src", imageURL + "?=" + d.getTime()); } checkImageUrl();
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.