zborisau@gmail.com wrote:
[snip]
[color=blue]
> var image1 = document.getElementById("scheck1");
> image1.src = "www.server1.com/image1px.gif";
> image1.onload = function() {
> isServer1=true;
> };[/color]
I've seen other order way to code :
var image1 = document.getElementById("scheck1");
image1.onload = function() {
isServer1=true;
};
image1.onabort = function() {
showError("failed to connect");
};
image1.src = "www.server1.com/image1px.gif";
[snip]
[color=blue]
> AND NOW PROBLEM:
>
> firefox works beautiful with this code.
>
> internet explorer (i am using ver 6) does not work under one case:
>
> server0 - is offline
> server1 - is offline
> server2 - is online
>
> IE tries to download all three images and whilst first two cannot be
> downloaded, it downloads third one no problem, but the onload event for
> the 3rd image is never fired unless the first two images has
> timeout-ed.[/color]
if to set the onload and onabort(IE only) functions
before calling images (src) doesn't solve your problem
do what you expect :
[color=blue]
> To correct this problem i believe that I have to cancel image loading
> after some timeout time (in my cae it is 10 seconds).
>
> So far I have not got any ideas how to do that.[/color]
image1.src = ''; ? ?
[color=blue]
> If you have any solution for such a problem, or may be u have another
> solution on how to pick up the first available server (in some order of
> priority) and redirect user to that server (using javascript strictly)
> - I will gladly appreciate all comments.[/color]
No idea if that could work :
// ***************
serverSpeed = '';
imagesLoader = new Array();
I = new Array();
Ii=0;
ind = new Object();
function imageLoaded(nameServer) {
ind[nameServer]=0;
I[Ii] = new Image();
I[Ii].src = 'www.'+nameServer+'/image1px.gif';
imageLoading(nameServer,I[Ii]);
Ii++;
}
function imageLoading(nameServer,imag) {
if(!imag.complete && ind[nameServer]<50)
imagesLoader[name] = setTimeout('imageLoaded('+
nameServer+','+imag+')',200);
else
if(!imag.complete) {
clearTimeout(imagesLoader[nameServer]);
alert('image from '+nameServer+' abort');
return;
}
else
serverSpeed += severName+'='+ind[nameServer]+',';
ind[nameServer]++ ;
}
imageLoaded('server0');
imageLoaded('server1');
imageLoaded('server2');
setTimeout( function() {
if(serverSpeed=='') {
alert('all servers kaput');
return;
}
serverSpeed = serverSpeed.split(',');
for(var i=0, L=serverSpeed.length;i<L;i++)
serverSpeed[i]=serverSpeed[i].split('=');
serverSpeed.sort( function by_name(a,b) {
if (a[1] < b[1] ) { return -1; }
if (a[1] > b[1] ) { return 1; }
return 0;
}
);
fasterServer = serverSpeed[0][0];
alert('winner = '+
serverSpeed[0][0]+
'\ntime : '+serverSpeed[0][1]+' 1/5s');
location.href = 'http://www.'+fasterServer+'/';
}
, 10500);
//*******
--
Stephane Moriaux et son [moins] vieux Mac