We help IT Professionals succeed at work.
Get Started

Javascript (IE) Image Size Problem.

Chris Coleman
on
370 Views
Last Modified: 2012-05-11
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;
}
Comment
Watch Question
Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE