If an image is generated in the DOM, either manually or thru an XMLHttpRequest, querying that image for it's height & width no longer works (it did earlier). Here's a test case: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Image bug</title> <script type="text/javascript"> function test() { var srcImage = document.createElement("img"); srcImage.setAttribute("src","http://images.apple.com/macosx/images/indextop20060109.jpg"); //Source image is 670x275 var image = new Image(); image.src=srcImage.getAttribute("src"); image.onload=testImage(image); } function testImage(image) { //The image object should return a width of 670 since the image has been loaded alert("Image " + image.src+" width:"+image.width); //It actually returns 0 } </script> </head> <body onload="test();"> </body> </html> The alert box returns width: 0. The alert box should have returned width: 670. If the image is loaded already such as: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Image bug</title> <script type="text/javascript"> function test() { var srcImage = document.createElement("img"); srcImage.setAttribute("src","http://images.apple.com/macosx/images/indextop20060109.jpg"); //Source image is 670x275 var image = new Image(); image.src=srcImage.getAttribute("src"); image.onload=testImage(image); } function testImage(image) { //The image object should return a width of 670 since the image has been loaded alert("Image " + image.src+" width:"+image.width); //It actually returns 0 } </script> </head> <body onload="test();"> <img id="testSubject" src="http://images.apple.com/macosx/images/indextop20060109.jpg" alt="OS X" /> </body> </html> The alert box returns width: 670. Since the script is explicitedly displaying the alert only after the onload of the image, it should display properly.
Created attachment 7410 [details] test 1
Created attachment 7411 [details] test 2
Reporter, do you know when the behavior has changed? I'm getting identical results from stock 10.4.5 and ToT. Actually, Firefox also reports zero width once after a relaunch.
I was using this code in a widget developed and released under 10.4.4. Thus, I believe the change occurred with 10.4.5 and it's update to the safari webkit.
My brief testing shows that Camino demonstrates identical behaviour to WebKit in always returning zero for the width, while Firefox returns zero when first run and then the correct value thereafter. I'm not sure if this should be considered a bug.
Joost has convinced me this is a bug.
Both tests now report an image width of 670 with r35417, so this may be fixed.