SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Image preloading: IE reporting wrong image size.

    I'm doing some simple image preloading, but for some reason that I cannot for the life of me figure out, IE is reporting erroneous dimensions for the image:
    Code:
        var prel = new Image();
        prel.onload = function() {
            alert(prel.width + ' ' + prel.height);
        }
        prel.src = 'image.jpg';
    It's part of some longer code, so I just tested the above snippet by itself with no other JS to influence it and IE is still reporting the wrong dimensions. The odd thing is it seems to do it only for some images I try and in some cases the difference from reality varies by over 100px, in others by only a few px.

    I've cleared my cache approximately 1 billion times, restarted the PC and still the erroneous dimensions are being reported. Other browsers are behaving.

    Any idea what it could be?

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try setting the dimensions when you create the image
    Code:
    var prel = new Image(300, 100);

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That solves the problem for a single image, but in the real application it's impossible to know the size of the image beforehand, unfortunately. There are loads of images of varying sizes and I'm looping through them.

    Not only does IE report the wrong dimensions (and only for some images), but the values for each image are always the same, so it doesn't seem like IE is behaving completely erratically.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •