Re: help with design - reload image on image load; avoid infinite loop
- From: Thomas 'PointedEars' Lahn <PointedEars@xxxxxx>
- Date: Wed, 17 Jun 2009 19:50:27 +0200
lawpoop wrote:
Hello! I have a page with a graph image that's dynamically generated.
It takes a while for the php script to compile the data and spit out
the graph, so what I want to do is have an ajax "loading" image as the
default image, and then call an xml http request to change the source
to the graph image.
Requests are not called, and this is not only an unreliable but also an
entirely ridiculous approach. See below.
However, I was using the onLoad() event for the image,
There is no such thing. Maybe you mean the `load' event or the `onload'
event handler.
and of course, once my graph loaded, it would call the onLoad() event
again, reload the graph, and so on.
That's a know issue, particularly in Opera. Just remove the event listener
in the event listener.
I could implement a check not to reload the graph once the source
image had change from the "loading" image, but there's still an
infinite loop of image checking going on, even if the page doesn't
appear to change.
Unlikely.
I looked and w3schools says
.... what you want to ignore. W3Schools is junk.
that the onLoad() event only works with
the tags <body>, <frame>, <frameset>, <iframe>, <img>, and <link> .
Like you, they do not know what they are talking about.
1. Event targets are elements, not tags. (Elements consist of tags,
and sometimes content.)
2. The (X)HTML `frame', `iframe', `img' and `link' elements do not
have an `onload' attribute. Specifying it there creates invalid
markup.
3. It depends on the DOM which elements support the `load' event,
and which DOM objects may also support the proprietary `onload'
event-handler property.
I'm loading this image inside of a div,
Irrelevant.
my testing with the body tag doesn't seem to work.
The `load' event of the `body' element (represented by an object that would
implement the HTMLBodyElement interface) occurs when the (X)HTML document
body has loaded. That does not necessarily include the condition that all
images have been downloaded and rendered completely. You can assume,
though, that the corresponding DOM object will be available by then.
Obviously I can't use img.
You can, but you need to add the event listener dynamically (in the `load'
event listener of the `body' element), and it is possible that the image has
been downloaded and rendered by then. (AFAIK the only alternative is
invalid markup; even XHTML is not /that/ extensible.)
I don't think I want to use frames
You are right on this for a change.
How should I design the site to get this functionality?
You don't. This approach only makes sense if you are using XHR to retrieve
the information in the first place. Because, in the worst case you are
increasing the time that passes before the actual image is shown.
You can, however, use a listener for the proprietary `error' event of image
objects to replace the image with something else (that you know has a high
probability to be accessible) in case of an error. The corresponding
proprietary event-handler property is named `onerror'.
PointedEars
.
- References:
- Prev by Date: Re: help with design - reload image on image load; avoid infinite loop
- Next by Date: Re: how to put in an HTML element the content of a txt file?
- Previous by thread: Re: help with design - reload image on image load; avoid infinite loop
- Next by thread: Re: help with design - reload image on image load; avoid infinite loop
- Index(es):
Relevant Pages
|