how to check if the picture already output?

Discussion in 'JavaScript' started by KennyTE, Jul 7, 2007.

  1. #1
    Hi everyone,

    Let say, i have a page that output this a several image, how to check weather a certain image already successfully load to user browser?

    example image:

    <div><img src='http://www.nasa.gov/images/content/84857main_EC04-0325-23_lg.jpg' width='336' height='280'></div>

    i need to return a value is the picture finish load.

    Thanks.
     
    KennyTE, Jul 7, 2007 IP
  2. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    You can test the .complete property, but it can be misleading.
    It's more reliable to use the onload handler, either to add a property to the image object or to call some other function:
    
    <img name='img1' onload="this.hasLoaded=true" .....>
    
    if( document.images.img1.hasLoaded )
     ...
    Code (markup):
     
    Logic Ali, Jul 8, 2007 IP