Feedback on: irt.org FAQ Knowledge Base Q52
Worth:
Very worth reading
Comments:
Legal
Worth:
Worth reading
Length:
Too short
Technical:
Just right
Comments:
You can also use the Image() object to test for the existence of a generic image (or any number of images) without ever displaying them on the page:
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!');
}
This can be useful if, for example, the user must specify an image and you want to check whether it exists before submitting the form.
Worth:
Worth reading
Comments:
This solution dosn't seem to do it in MSIE, do you know a way to do it?
Worth:
Very worth reading
Length:
Too long
Technical:
Too technical
Comments:
With regard to my previous comment, this code only seems to work in Netscape 4. It no longer runs in Netscape 6, or in IE.
Worth:
Very worth reading
Length:
Just right
Technical:
Just right
Comments:
image.onLoad works for Netscape but for IE (at least for 5.5) you need to use image.onload (lowercase).
Comments:
How could this be used to display an alternate graphic image if the specified image in a <img> tag doesn't exits? Assume that a standard image will be loaded for the alternate image.
Worth:
Length:
Technical:
Just right
Comments:
An another way to do this...
function ImageTest(URL) {
var
MyImage = new Image();
I = 0;
MyImage.onerror = DoesntExists;
MyImage.src = URL;
if(I > 0){
return('<your another picture link>');
}
function DoesntExists(){
I++;
}
return(URL);
}
Worth:
Length:
Technical:
Comments:
onerror somehow doesn't work with some browsers. Wonder if there's a way to check if there was an error in onload instead...