SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    $books++ == true matsko's Avatar
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    imageObject.onload = function() == doesn't work in IE

    I scripted a function in javascript that takes an image src and then sets a new Image() to have the src. Once the image is loaded, it gets displayed.

    Code:
    var new_image = new Image();
    new_image.src=newImageSrc;
    new_image.onload = function() { ... }
    I noticed that the code works in firefox, but not in IE. I found this to be a problem since the onload attribute works perfectly fine when coded into the html for Internet Explorer.

    However, it doesn't work when coded through javascript.

    Is there anyway to get the onload listener for images to work in IE?
    I can't believe I ate the whole thing

  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)
    Following works fine in Firefox and IE 6
    Code:
    <html>
    <body>
    <script>
    var new_image = new Image();
    new_image.src = "http://www.sitepoint.com/forums/image.php?u=55537&dateline=1134619804";
    new_image.onload = function() { document.body.appendChild(new_image); }
    </script>
    </body>
    </html>

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hm... try to assign your onload function before assigning src element to the image object. that should work fine.

  4. #4
    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)
    There is no need to do that though... The effect will be the same.


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
  •