为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

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