troubleshooting Question

Javascript (IE) Image Size Problem.

Avatar of Chris Coleman
Chris ColemanFlag for United Kingdom of Great Britain and Northern Ireland asked on
JavaScript
8 Comments1 Solution373 ViewsLast Modified:
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;
}
ASKER CERTIFIED SOLUTION
leakim971
Multitechnician
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros