开发者

javascript onerror function doesn't execute in the normal sequential flow?

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 a开发者_StackOverflow社区nd 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


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: Having troubles preloading images with javascript

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜