SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript problem with Internet Explorer (v8)

    I all, i am making a web site which has a menu, and when you click on a menu item, a thumbnail list should appear. I am trying to preload all the images that should appear and then display them. It works fine on every browser except IE (i have version 8). I have put together the code for anyone willing to take a look here: http://jsfiddle.net/THpgM/2/

    I think the problem lies in this piece of code (which is near the bottom of the first function in the fiddle)

    Code:
    img.onload = (function(i){ 
      // code here is executed
      return function(){
        // code here is not
        ++totalLoaded;
        document.getElementById("li" + i).style.height = this.height + "px";
        document.getElementById("li" + i).setAttribute("data-height", this.height);
    
        if(totalLoaded == totalThumbs){
          // do some stuff
        }
      };
    })(i);
    I have spent like 2 days trying to figure this out. If someone could please help me with this it would be greatly appreciated.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by abrakatabra83 View Post
    I have spent like 2 days trying to figure this out. If someone could please help me with this it would be greatly appreciated.
    IE8 only fires the load event on an image if it has to download that image from the server.
    If it gets the image from its cache, it doesn't fire the load event.

    That's the cause of the problem, but I'm not so sure as to a viable solution, other than using the document onload event.

    You may find some viable ideas though in this post: http://stackoverflow.com/questions/1...rk-well-in-ie7
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    May 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Paul. You are spot on about the problem, someone else happened to help me with this before you, and all i had to do was to place img.src before img.onload (i had img.onload before img.src).

    Thanks anyway =)


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
  •