JellyON wrote:
Well, it sounds right :-) I've just replaced the if by a
setTimeout(function(){this.src='http://host.com/cgi-bin/counter.exe?
color=red&font=6';});
because it's better for delaying counter call and I didn't seen the
reason why for testing "TempTransparent.gif" presence (obviously always
here). Maybe something I've missed ?
I did not mean to test for "TempTransparent.gif". The idea was to have
TempTransparent.gif loaded right away so user does not see empty image
frame. And right upon the TempTransparent.gif load you request the
counter picture so it appears on the page when ready. setTimeout is an
option but why make things more difficult as they should be? ;-)
Well, now, it stay just a thing : I would like to display another DIV
(which contain a text like "Number of hits : ") only if counter call
succeeded. The question is not to know how to show the DIV (simply
change the visibility style attribute), but what to test. That is the
question !
Error event supported by images since Netscape 3 - what else?
The combined code could be:
....
<img name="myCounter" src="myTransparent.gif" width="128" height="32"
onload="
if (this.src == 'myTransparent.gif') {
this.src='http://host.com/cgi-bin/counter.exe?color=red&font=6';
this.failedToLoad=false;
}
else {
document.getElementById('myDiv').style.visibility = 'visible';
}"
onerror="
this.src='myOops.gif';
this.failedToLoad=true;"
/>
....
As you cannot predict when exactly the counter will arrive, you better
let counter itself to make your <DIV> to appear, not vice versa.
To check the situation *later* (is counter loaded? is div displayed?)
you can always check the custom property failedToLoad:
if (document.images['myCounter'].failedToLoad) {
// I got some problems
}
Unlikely in your case, but be careful with animated gif's: they produce
new "load" event on each animation cicle (a very old GIF98a bug which
will never be fixed now).
Also make sure that at least 'myOops.gif' is always available,
otherwise you'll put your script into onerror loop. It also can be
fixed programmatically, but easier and better simply to have this image
on your server.