<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>9582</bug_id>
          
          <creation_ts>2006-06-25 13:37:53 -0700</creation_ts>
          <short_desc>img.onload event ONLY fires when .src changes</short_desc>
          <delta_ts>2024-05-21 03:49:26 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>417.x</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.4</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jeffrey Schrab">jschrab</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>bfulgham</cc>
    
    <cc>crschmidt</cc>
    
    <cc>dacarson</cc>
    
    <cc>eric</cc>
    
    <cc>hyongyoub.kim</cc>
    
    <cc>ian</cc>
    
    <cc>mitz</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>47134</commentid>
    <comment_count>0</comment_count>
    <who name="Jeffrey Schrab">jschrab</who>
    <bug_when>2006-06-25 13:37:53 -0700</bug_when>
    <thetext>Consider the following example:

------------------------------------------
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
        &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
	function dothis() {
		document.getElementById(&apos;demoImage&apos;).onload = function() { alert(&apos;done&apos;); }
		document.getElementById(&apos;demoImage&apos;).src = &quot;http://images.apple.com/main/elements/homeiconus.gif&quot;;

	}
	function dothat() {
		document.getElementById(&apos;demoImage&apos;).onload = function() { alert(&apos;done&apos;); }
		document.getElementById(&apos;demoImage&apos;).src = &quot;http://images.apple.com/main/elements/homeiconus.gif&quot;;
	}
	&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
	&lt;a href=&quot;#&quot; onclick=&quot;dothis();&quot;&gt;dothis&lt;/a&gt; | &lt;a href=&quot;#&quot; onclick=&quot;dothat();&quot;&gt;dothat&lt;/a&gt;&lt;br /&gt;
	&lt;img src=&quot;http://images.apple.com/main/elements/homeiconus.gif&quot; id=&quot;demoImage&quot; alt=&quot;&quot; /&gt;
&lt;/body&gt;
&lt;/html&gt;
------------------------------------------

It would appear that onload events for img elements (possibly more) only will fire when there is an actual change to the .src in the above example.  The &quot;alert()&apos;s&quot; in the onload functions never fire because the value of src changes.  This is not how other major browsers (IE 6.0 and Firefox 1.5 tested) behave - onload events always fire after they are complete, even if they don&apos;t do a whole lot in the case of unchanged content.

There is a work around but it&apos;s not nice:

------------------------------------------
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
        &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
	function dothis() {
		document.getElementById(&apos;demoImage&apos;).onload = function() { alert(&apos;done&apos;); }
		document.getElementById(&apos;demoImage&apos;).src = &quot;http://images.apple.com/main/elements/homeiconus.gif?random=&quot;+Math.random();

	}
	function dothat() {
		document.getElementById(&apos;demoImage&apos;).onload = function() { alert(&apos;done&apos;); }
		document.getElementById(&apos;demoImage&apos;).src = &quot;http://images.apple.com/main/elements/homeiconus.gif?random=&quot;+Math.random();
	}
	&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
	&lt;a href=&quot;#&quot; onclick=&quot;dothis();&quot;&gt;dothis&lt;/a&gt; | &lt;a href=&quot;#&quot; onclick=&quot;dothat();&quot;&gt;dothat&lt;/a&gt;&lt;br /&gt;
	&lt;img src=&quot;http://images.apple.com/main/elements/homeiconus.gif&quot; id=&quot;demoImage&quot; alt=&quot;&quot; /&gt;
&lt;/body&gt;
&lt;/html&gt;
------------------------------------------

With differing URL&apos;s, the src is different so onload events will fire off.  But this is a waste - the browser goes off the server for images that it really doesn&apos;t need, just so events will fire off.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>47230</commentid>
    <comment_count>1</comment_count>
      <attachid>9042</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2006-06-26 02:10:39 -0700</bug_when>
    <thetext>Created attachment 9042
test case

Same test, as an attachment.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>47234</commentid>
    <comment_count>2</comment_count>
    <who name="">mitz</who>
    <bug_when>2006-06-26 02:29:45 -0700</bug_when>
    <thetext>IIRC, the DOM specification doesn&apos;t include load events for IMG elements, so I think whether the current behavior is a bug or not is mostly a question of what Firefox and IE (plan to) do.

At least, the behavior of SCRIPT and other load events should be considered at the same time.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48133</commentid>
    <comment_count>3</comment_count>
    <who name="David Carson">dacarson</who>
    <bug_when>2006-07-03 19:46:23 -0700</bug_when>
    <thetext>I wonder if the onLoad event should fire when 
(a) the first block of data arrives, or 
(b) when the full response has arrived or 
(c) when the image has been converted to a platform bitmap or 
(d) when it has been rendered.
Comment #0 says that it fires when it is complete - but what is complete?
If the image is not visible, then it may not be loaded. If the image is hidden, then it may not be fully converted to a bitmap, maybe just the height and width is available at this point.
Need to do some testing with IE and FF.


</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48178</commentid>
    <comment_count>4</comment_count>
    <who name="Jeffrey Schrab">jschrab</who>
    <bug_when>2006-07-04 09:48:06 -0700</bug_when>
    <thetext>I would like to make motion that it should be &quot;(d) when it has been rendered.&quot;  While it may seem selfish for me to say so, my real-world need that lead to the discovery of this bug/quirk was in an effort to implement some DHTML cross-fade effects.  I wanted to make sure that my opacity=0 image was loaded before my transition began.

It would seem to me that the usefulness of .onload, particularly for images, is to be notified that an image is ready-to-go.  And ready-to-go, I would say, means rendered.  Of course my case here is for a transparent image (via opacity style) or otherwise not visible image may lead to a fine point of &quot;what do you mean by &apos;rendered&apos;?&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48203</commentid>
    <comment_count>5</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2006-07-04 15:37:09 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; I wonder if the onLoad event should fire when 
&gt; (a) the first block of data arrives, or 
&gt; (b) when the full response has arrived or 
&gt; (c) when the image has been converted to a platform bitmap or 
&gt; (d) when it has been rendered.

What do other browsers do?  Can we tell what MSIE and Firefox do?

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58500</commentid>
    <comment_count>6</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2007-10-14 06:21:18 -0700</bug_when>
    <thetext>*** Bug 15499 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58501</commentid>
    <comment_count>7</comment_count>
    <who name="Christopher Schmidt">crschmidt</who>
    <bug_when>2007-10-14 06:37:42 -0700</bug_when>
    <thetext>My experience with FF + IE has always been &apos;at the time onload is called, swapping the image from display:none to display:block results in a fully rendered image being displayed.

That probably only makes it clear that it&apos;s not &apos;a&apos;, described below, since anything else could happen within a repaint, and there&apos;s no way to tell the difference visually.

The current behavior in Safari seems to be matched by Opera. This was reported as part of the OpenLayers project:

http://trac.openlayers.org/ticket/758

(I would love to see this fixed, as, at the moment, OpenLayers is relatively unusable under Safari for many users.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58512</commentid>
    <comment_count>8</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2007-10-14 10:47:00 -0700</bug_when>
    <thetext>This is kinda related to bug 15484.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1188495</commentid>
    <comment_count>9</comment_count>
    <who name="Hyongyoub Kim">hyongyoub.kim</who>
    <bug_when>2016-04-28 20:36:31 -0700</bug_when>
    <thetext>I know this issue has seen no action for 9 years. Here is a ping that this issue does matter in the real world. Many sites use this &quot;load the same source twice + onload event&quot; technique to load images asynchronously and then display them when they are already in the memory cache.

Looks like Chromium fixed this last year.

https://codereview.chromium.org/1047563002

The second load event does not fire because the following check in ImageLoader.

http://trac.webkit.org/browser/trunk/Source/WebCore/loader/ImageLoader.cpp#L217

Tried simply pretending the images are always different. It seems to work okay, but not sure about any side effects this would have on CachedImage::didAddClient and CachedImage::didRemoveClient.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1881128</commentid>
    <comment_count>10</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-07-06 14:45:52 -0700</bug_when>
    <thetext>&lt;rdar://problem/96549817&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2036697</commentid>
    <comment_count>11</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2024-05-21 03:49:26 -0700</bug_when>
    <thetext>I took test cases from Blink commit and it seems that WebKit ToT (279051@main) passes them now.

Blink Commit - https://github.com/chromium/chromium/commit/3a2965e93805f4cf213b8c1f84ed8141145f951b

It would be good to import these tests IMO.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>9042</attachid>
            <date>2006-06-26 02:10:39 -0700</date>
            <delta_ts>2006-06-26 02:10:39 -0700</delta_ts>
            <desc>test case</desc>
            <filename>img-onload.xhtml</filename>
            <type>application/xhtml+xml</type>
            <size>986</size>
            <attacher name="Alexey Proskuryakov">ap</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBYSFRNTCAxLjAgVHJhbnNpdGlvbmFs
Ly9FTiIKICAgICAgICAiaHR0cDovL3d3dy53My5vcmcvVFIveGh0bWwxL0RURC94aHRtbDEtdHJh
bnNpdGlvbmFsLmR0ZCI+Cgo8aHRtbCB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94aHRt
bCIgeG1sOmxhbmc9ImVuIiBsYW5nPSJlbiI+CjxoZWFkPgogICAgICAgIDxzY3JpcHQgdHlwZT0i
dGV4dC9qYXZhc2NyaXB0Ij4KICAgICAgICBmdW5jdGlvbiBkb3RoaXMoKSB7CiAgICAgICAgICAg
ICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnZGVtb0ltYWdlJykub25sb2FkID0gZnVuY3Rp
b24oKSB7IGFsZXJ0KCdkb25lJyk7IH0KICAgICAgICAgICAgICAgIGRvY3VtZW50LmdldEVsZW1l
bnRCeUlkKCdkZW1vSW1hZ2UnKS5zcmMgPSAiaHR0cDovL2ltYWdlcy5hcHBsZS5jb20vbWFpbi9l
bGVtZW50cy9ob21laWNvbnVzLmdpZiI7CgogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBkb3Ro
YXQoKSB7CiAgICAgICAgICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnZGVtb0ltYWdl
Jykub25sb2FkID0gZnVuY3Rpb24oKSB7IGFsZXJ0KCdkb25lJyk7IH0KICAgICAgICAgICAgICAg
IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdkZW1vSW1hZ2UnKS5zcmMgPSAiaHR0cDovL2ltYWdl
cy5hcHBsZS5jb20vbWFpbi9lbGVtZW50cy9ob21laWNvbnVzLmdpZiI7CiAgICAgICAgfQogICAg
ICAgIDwvc2NyaXB0Pgo8L2hlYWQ+Cgo8Ym9keT4KICAgICAgICA8YSBocmVmPSIjIiBvbmNsaWNr
PSJkb3RoaXMoKTsiPmRvdGhpczwvYT4gfCA8YSBocmVmPSIjIiBvbmNsaWNrPSJkb3RoYXQoKTsi
PmRvdGhhdDwvYT48YnIgLz4KICAgICAgICA8aW1nIHNyYz0iaHR0cDovL2ltYWdlcy5hcHBsZS5j
b20vbWFpbi9lbGVtZW50cy9ob21laWNvbnVzLmdpZiIgaWQ9ImRlbW9JbWFnZSIgYWx0PSIiIC8+
CjwvYm9keT4KPC9odG1sPgo=
</data>

          </attachment>
      

    </bug>

</bugzilla>