Wrong image dimensions when it's dynamically loaded on a page the 1st time
- by Nikita Barsukov
I have the following piece of Javascript code on my web-page
var central_image = document.createElement("img")
central_image.setAttribute("src", imgs[curr_image_no - 1]);
central_image.setAttribute("name", "jpeg");
document.getElementById("photo").appendChild(central_image);
central_image.onload = getDimensions(); //function that alerts image dimensions
Now, when the central_image is loaded for the 1st time in Firefox, its height always equals to 0. In IE its dimensions are 28 x 30 pixels. When I reload image, its dimensions are OK in both browsers.
I guess the problem is that function getDimensions() starts before image was loaded completely. How to change that?