Hi,
I'm having a bit of a problem which is now driving me mad. Basically, I want to know whether the path to an image is correct... and if not display a "not found" image. It should be simple but... all the code I've seen on the net uses the onerror event - yet it fires regardless of whether the images exists or not.
Here's my test code:
If you run it you'll see that both the events fire - or at least they do on my machine (IE6). If you put a nonsense URL in... they still fire! Can anyone help, all I need is a way to be sure that an image exists or not. If there's a better way (one with a different event I can capture) that'd be great.
Thanks in advance
Darren Jones
I'm having a bit of a problem which is now driving me mad. Basically, I want to know whether the path to an image is correct... and if not display a "not found" image. It should be simple but... all the code I've seen on the net uses the onerror event - yet it fires regardless of whether the images exists or not.
Here's my test code:
Code:
testImage("path/folder/testimageurl.gif");
function testImage(URL) {
var tester=new Image();
tester.onLoad=isGood();
tester.onError=isBad();
tester.src=URL;
}
function isGood() {alert('That image exists!');}
function isBad() {alert('That image does no exist!');}
If you run it you'll see that both the events fire - or at least they do on my machine (IE6). If you put a nonsense URL in... they still fire! Can anyone help, all I need is a way to be sure that an image exists or not. If there's a better way (one with a different event I can capture) that'd be great.
Thanks in advance
Darren Jones