|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I need to be able to check in Javascript whether an image exists and have been trying to use the onerror event, but just can't get it to work. Does anyone have any suggestions?
The code I have been using is as follows. What happens is that both the onerror AND the onload events execute. I'm using IE6 and Navigator 6. Code:
function testImage {
var tester=new Image();
tester.onLoad=isGGood();
tester.onError=isBBad();
tester.src="testimage.jpg";
}
function isGGood() {
alert('That image exists!');
}
function isBBad() {
alert('That image does not exist!');
}
|
|
|||
|
That syntax is incorrect. You can't assign event handlers in that way. You are also missing parentheses on your testImage function.
Try Code:
function testImage() {
var tester=new Image();
tester.onload=isGGood;
tester.onerror=isBBad;
tester.src="testimage.jpg";
}
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2010 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |