Version: 3.5.2 (using KDE KDE 3.5.2) Installed from: Slackware Packages OS: Linux The KHTML/KJS engine does not appear to handle Element.(offset|client)(Width|Height|Top|Left) properly when an element is created and sized within the same function. Example (test.png has an aspect ratio of 3:2): <html> <body> <script> function test() { var I = document.getElementById("image"); var imgElem=document.createElement("img"); imgElem.src="test.png"; imgElem.style.width=24; imgElem.id="image1"; I.parentNode.replaceChild(imgElem,I); // This first alert, under Firefox and IE, pops up as "16" // Under Konqy, it pops up as "0" alert(imgElem.clientHeight); } </script> <a id="image" href="javascript: test();">Click Me</a><br /> <a href="javascript: alert(document.getElementById('image1').clientHeight);">Click Me next</a> <!-- The second alert is correctly "16" in FF/IE and Konq. --> </body> </html>
I am not quite convinced this is a bug, since at the point you query the size, the image is generally not loaded yet, so the renderer has no reason to know the aspect ratio/the other direction. And I don't see how it's fixable in all cases, since the image may be loading from a very slow server. Do you know what would firefox do in that case by any chance? What would a real-life use look like?
A firefox-only example of real life use is here: http://www.fordi.org/comics. It's actually what I'm trying to get working in Konqy. It doesn't yet work in IE, but that's more a w3c compliance issue than an offset* issue. Your argument doesn't completely explain the failed behavior; an (png/gif/jpeg)'s size can generally be found within its header. In any case, the above example should work locally (when I'm prototyping), as it does with other browsers. On very slow servers, I wouldn't expect it to always work, but on a very slow server, you can't really expect much to work properly.
To see the header, one has to start decoding the header. And coincidentally, this testcase doesn't work reliably in firefox either: the first time you open it, it reports clientWidth x clientHeight as 24x24, not 24x16. Basically, right now you're IMHO relying on pretty subtle implementation details and writing code that has a race condition in it anyway.
<a id="image" href="javascript: test();">Click Me</a><br /> The height reported by 'alert(imgElem.clientHeight);' should be the heigth of the content of the <a> tag's value and that is 'Click Me' here. The font height determine the amount of pixels it need. Only if no innerTxt/innerHTML for A then the height is 0 (or null) else it is the height of the innerTxt/innerHTML (i.e. a image tag to click on).
Gotcha. I think I get now that the offset* params wouldn't work - unless locally - until the image.onload event fires. I'm modifying my code to fix this race condition.
It still behaves the same way in trunk r776286. However it seems to be a site design issue. Close bug as INVALID?
Message from the Bugsquad and Konqueror teams: This bug is closed as outdated, as we do not have the manpower to maintain the KDE3 version anymore. If you still can reproduce this issue with Konqueror 4.8.4 or later, please open a new report. Thank you for your understanding.