views:

29

answers:

1

hello,

my code is something like this:

function func1()  {

     document.getElementById("img").src="pic.jpg";
     ---stament2---;
}

document.getElementById("img").onerror="func2()";

In other browser, if there is no pic.jpg, func2() is executed and AFTER that, stament2 is executed; in opera if there is an error loading the image, func2() is executed after stament2.

Why did they did it like this? Is there any advantage? IS THERE A WAY to make it run the function called by onerror right when it's called and not after other statements?

if someone could please help....

Does jquery or other library have a crossbrowser solution for onerror applied to images? hmmm...must learn some jquery

thanks

+1  A: 

You can put statement2 into a separate function and call it at the end of the onLoad of images as well as the end of the onError. Check out: http://stackoverflow.com/questions/922309/having-troubles-preloading-images-with-javascript

Detect
ahaaaa...it makes perfect sense ...i'l try it....thank you sir :)
bogdan
worked great...i'm a beginner but i think it's an elegant solution...thanks again
bogdan
you're welcome :)
Detect