W3C home > Mailing lists > Public > public-html@w3.org > March 2012

Spec behavior for img.src sets is not quite web-compatible

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Fri, 16 Mar 2012 00:44:06 -0400
Message-ID: <4F62C516.2000707@mit.edu>
To: HTML WG <public-html@w3.org>
Consider the following testcase:

<!DOCTYPE html>
window.onload = function() {
   var img = document.querySelector("img");
   img.src = 
   alert(img.width + " " + img.height);

Every non-Gecko UA alerts "32 32".  Gecko used to do the same thing 
before Firefox 4.  At that point we switched to doing what the spec 
calls for here, which is that the src set starts an async fetch and the 
image size does not update until the fetch completes.

Unfortunately, this does not seem to be web-compatible.  People expect 
their preloaded images to synchronously update the width and height when 
src is set to them.

I'm probably going to change Gecko to do that.  I have no idea how to 
spec it, though, because the spec doesn't have any concept of images 
being preloaded, and I'm not quite sure it should.  :(


P.S.  The behavior is the same with non-data: URIs; the data: URIs just 
made it easier to construct a standalone testcase.
Received on Friday, 16 March 2012 04:44:36 UTC

This archive was generated by hypermail 2.4.0 : Saturday, 9 October 2021 18:45:50 UTC