I have a simple piece of code which downloads an image and then obtains the images width -
works perfectly in Opera and Firefox, but in IE it sometimes produces an incorrect image dimension, which is a problem because I need the image dimensions to set a div that eventually contains the image as a background.
function setGlass(imgObj, show) {
// Translate the foreground image name into a background image name for the glass.
var newBackImg = bigImageDirectory + imgObj.src.substr(preViewImageDirectory.length);
var bImage = new Image();
bImage.onload = function () {
bImage.onload = "";
// For testing the following sometimes returns an incorrect (too big) dimension iin IE ?
alert(bImage.width);
if (show) {
// Set or replace the positioning imgObject.
p = new positionGlass (true, imgObj, bImage);
}
// The image itself remains in the browser's cache.
delete bImage;
}
bImage.src = newBackImg;
return true;
}
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.