Mozilla 도움말 검색

고객 지원 사기를 피하세요. 저희는 여러분께 절대로 전화를 걸거나 문자를 보내거나 개인 정보를 공유하도록 요청하지 않습니다. "악용 사례 신고"옵션을 사용하여 의심스러운 활동을 신고해 주세요.

Learn More

After accessing Image.complete, Image.onload does not fire.

  • 3 답장
  • 3 이 문제를 만남
  • 9 보기
  • 최종 답변자: knorretje

more options

JavaScript code that works under IE-9 and Chrome-16, but not under Firefox-9.0.1:

var slides = []; slides[0] = new Image(); slides[0].src = fileNames[0];

var tmp = slides[0].complete;

  slides[0].onerror = function(){
                         alert("While downloading\n"+
                                "           " +fileNames[0]+
                                "\nerror occurred. Execution stops");
                         throw new Error("Network problem");
                      };
  alert("X " + tmp);
  alert("Y ");
  slides[0].onload  = function(){
                        alert(this.complete);
                         if (winStarted) winStart()
                         else window.onload = winStart;
                     };

The alerts "X" and "Y" give output, but the onload branch is not taken. Onload branch is taken under IE-9 and Chrome 16.0.912.63.

JavaScript code that works under IE-9 and Chrome-16, but not under Firefox-9.0.1: var slides = []; slides[0] = new Image(); slides[0].src = fileNames[0]; var tmp = slides[0].complete; slides[0].onerror = function(){ alert("While downloading\n"+ " " +fileNames[0]+ "\nerror occurred. Execution stops"); throw new Error("Network problem"); }; alert("X " + tmp); alert("Y "); slides[0].onload = function(){ alert(this.complete); if (winStarted) winStart() else window.onload = winStart; }; The alerts "X" and "Y" give output, but the onload branch is not taken. Onload branch is taken under IE-9 and Chrome 16.0.912.63.

글쓴이 Paul.Wormer 수정일시

모든 댓글 (3)

more options

Could you create a working testcase on http://jsfiddle.net/ (save and post the link here), please.

more options

http://jsfiddle.net/paulwormer/wXN9p/

This fiddle alerts: FF-9 "Complete branch; Chrome-16 "Complete branch" + "Onload branch" ; IE-9 "Onload branch".

more options

There seems to be an onload for XUL images, but I can not find it for html images.
https://developer.mozilla.org/en/DOM/HTMLImageElement
https://developer.mozilla.org/en/DOM/element
https://developer.mozilla.org/en/XUL/image
Maybe you can use element.addEventListener instead. Something like:
s.myonload = function ....
s.addEventListener("load",s.myonload,false);
s.src = ...

https://developer.mozilla.org/en/DOM/element.addEventListener