Re: help with design - reload image on image load; avoid infinite loop



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
.



Relevant Pages

  • change avi source files in real-time
    ... this sample loads "wFileName" and play it. ... I want to stop current AVI and want to load new AVI file. ... // Register the graph in the Running Object Table ... // instead of allowing the Filter Graph Manager to render all pins. ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: DirectShow: fastest way to load another file to playout
    ... which had a Load method ... the graph, load another file, and start the graph again. ... all source filters I have seen. ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: web spider using mozilla and javascript
    ... the problem is that the window.open returns immediately after window is open, does not wait for page to be loaded and I can't figure out how to wait for the site to load. ... Of course it is a bit of a gamble as in the above sequence it would be possible that the document in the popup is loaded before the script in the other window manages to add its event listener. ... But as far as I have tested with Mozilla 1.7 the event listener is fired when a page from e.g. http://localhost/ loads another page from localhost while attempts to load a page from a different server did not fire the event listener although the JavaScript console shows no security error or warning. ...
    (comp.lang.javascript)
  • Re: DirectShow: fastest way to load another file to playout
    ... I would recommend to take a look at the MultiVMR9. ... the graph, load another file, and start the graph again. ... all source filters I have seen. ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: web spider using mozilla and javascript
    ... the problem is that the window.open returns immediately after window is open, does not wait for page to be loaded and I can't figure out how to wait for the site to load. ... You can try to attach an event listener to the returned window e.g. ... Of course it is a bit of a gamble as in the above sequence it would be possible that the document in the popup is loaded before the script in the other window manages to add its event listener. ... But as far as I have tested with Mozilla 1.7 the event listener is fired when a page from e.g. http://localhost/ loads another page from localhost while attempts to load a page from a different server did not fire the event listener although the JavaScript console shows no security error or warning. ...
    (comp.lang.javascript)