Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Detecting "image loaded successfully"

    I have a page with content.
    Upon a certain action, two images get updated/replaced.
    Because the images are on another server, it sometimes takes a couple of seconds.
    * I would like to block specific actions (click on a button/other image) UNTIL the images are loaded.
    * How do I detect when the images are done loading?
    Something like readyState, complete, or something?
    Any advice?

    Thanks in advance.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    624
    Thanks
    1
    Thanked 20 Times in 20 Posts
    For a single image, I use:
    Code:
    <img src="target.gif" width="8" height="8" onload="ItsOK();" onerror="ItsBad();" />

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The website is dynamic. That's why I need to use JavaScript.

    Let's say we have:
    Code:
    <img id='orimg' src='http://www.currentsite.com/img/item01.jpg' />
    and we change it using JavaScript:
    Code:
    <script type="text/javascript">
       function changePic() {
          var imgobj = document.getElementById('orimg');
          imgobj.src = 'http://www.othersite.com/img/item01.jpg';
       }
    </script>
    Is there a property I can check, to check the state (loading, loaded, error) ?
    Last edited by SlimShady; 12-21-2006 at 02:09 PM. Reason: html > code

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    624
    Thanks
    1
    Thanked 20 Times in 20 Posts
    You can reference an individual image with:
    Code:
    document.images['imageID']
    One of its properties is "complete" but I can't seem to reference it directly. Hmmm.


  •  

    Posting Permissions

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