Image Object complete not accurate?

Discussion in 'Javascript' started by Rob T, Nov 2, 2006.

  1. Rob T

    Rob T Guest

    I made an image slideshow with precaching that uses three overlapping
    div tags that each contain an img tag that can be accessed using
    getElementById(). If imgObj is my image object, I change imgObj.src to
    the image URL and I'm checking imgObj.complete to see if it has been
    loaded. The problem is that when I change an imgObj that previously
    held an image, complete will be true immediately after imgObj.src has
    been changed, regardless of whether it is loaded. Is there any way to
    avoid this or is there a way to destroy the old image object before I
    assign the new src URL?

    Rob
     
    Rob T, Nov 2, 2006
    #1
    1. Advertising

  2. Rob T

    Randy Webb Guest

    Rob T said the following on 11/2/2006 5:21 PM:
    > I made an image slideshow with precaching that uses three overlapping
    > div tags that each contain an img tag that can be accessed using
    > getElementById(). If imgObj is my image object, I change imgObj.src to
    > the image URL and I'm checking imgObj.complete to see if it has been
    > loaded. The problem is that when I change an imgObj that previously
    > held an image, complete will be true immediately after imgObj.src has
    > been changed, regardless of whether it is loaded. Is there any way to
    > avoid this or is there a way to destroy the old image object before I
    > assign the new src URL?


    Don't use the .complete, use .onload of the IMG object. And then look at
    the group FAQ with regards to cacheing. You can add the current time, in
    milliseconds, to the file name and it will be retrieved from the server.

    imgOjb.src = "someFile.png?" + new Date().getTime();

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Nov 2, 2006
    #2
    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. Jim Butler

    this seems too simple, to be accurate

    Jim Butler, Dec 31, 2003, in forum: ASP .Net
    Replies:
    9
    Views:
    560
    Wolfgang Kaml
    Jan 21, 2004
  2. mmquan
    Replies:
    11
    Views:
    694
    Michael Borgwardt
    Jul 1, 2004
  3. Amit
    Replies:
    1
    Views:
    427
    Andrew Thompson
    Sep 7, 2004
  4. Whitecrest

    Re: Most accurate browser for CSS?

    Whitecrest, Apr 1, 2004, in forum: HTML
    Replies:
    0
    Views:
    433
    Whitecrest
    Apr 1, 2004
  5. kchayka
    Replies:
    0
    Views:
    431
    kchayka
    Apr 2, 2004
Loading...

Share This Page