How to find that, image is loaded or not

Discussion in 'Javascript' started by balakrishnan.dinesh@gmail.com, Sep 5, 2006.

  1. Guest

    hi frnds,
    In my senario, My webpage will load dynamically from the
    server, Sometimes Images in my is not loading, how can i find , whether
    my image is loaded or not, through javascript.

    then the image tag will have the id as "imageId"

    I have putted alert as document.getElementById('imageId').
    eventhough the image is not loaded ,the alert showing it is a object.

    Can anyone tell me. how i will be indicated when image not
    loaded through a javascript alert.

    Rgrds
    Dinesh...
     
    , Sep 5, 2006
    #1
    1. Advertising

  2. Randy Webb Guest

    said the following on 9/5/2006 12:55 AM:
    > hi frnds,
    > In my senario, My webpage will load dynamically from the
    > server, Sometimes Images in my is not loading, how can i find , whether
    > my image is loaded or not, through javascript.
    >
    > then the image tag will have the id as "imageId"
    >
    > I have putted alert as document.getElementById('imageId').
    > eventhough the image is not loaded ,the alert showing it is a object.
    >
    > Can anyone tell me. how i will be indicated when image not
    > loaded through a javascript alert.


    Use the onload attribute of the img, along with the onerror event handler:

    <img onload="alert('It is loaded')"
    onerror="alert('There was a problem')"
    src="myImage.png">

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Sep 5, 2006
    #2
    1. Advertising

  3. Guest

    Hi Randy,

    Thanks for your suggestion, Here there is another problem
    when i implemented your idea .

    You ask me to put onerror event in image tag. what i did is,
    i have keep on refresh the page till the image loaded properly in
    onerror event. And i have many request on this same page , While
    refreshing the page all requests are repeatedly going again and again
    to the server.

    Is there anyother way to give request only for the image .
    Because i want the image to be loaded ,at the same time other request
    should go to server.

    Rgrds..
    Dinesh...
     
    , Sep 22, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcelo Birnbach [MS]
    Replies:
    0
    Views:
    3,327
    Marcelo Birnbach [MS]
    Jun 28, 2003
  2. Udo Corban
    Replies:
    0
    Views:
    3,850
    Udo Corban
    Jan 23, 2004
  3. Wybo Dekker
    Replies:
    1
    Views:
    361
    Yukihiro Matsumoto
    Nov 15, 2005
  4. guywmustang

    Javascript Image objects not loaded

    guywmustang, Sep 2, 2006, in forum: Javascript
    Replies:
    2
    Views:
    96
    guywmustang
    Sep 4, 2006
  5. Image is not loaded sometimes

    , Sep 4, 2006, in forum: Javascript
    Replies:
    0
    Views:
    83
Loading...

Share This Page