Re: Progress Events example

It would probably be better to add the event listeners before setting the  
href attribute, because if the image is cached, the UA might very well  
load it synchronously, or the load timeout might not be enough until the  
load listener is added.


Garrett Smith <dhtmlkitchen@gmail.com> escreveu:

>
> http://www.w3.org/TR/progress-events/#Using
>
> The example loads an image, and then subscribes to progress events:
>
> function showImage(imageHref) {
>        var image = document.getElementById('myImage');
>        image.setAttributeNS(xlinkNS, "href", imageHref);
>        image.addEventListener("progress",imageLoadProgress,false);
>        image.addEventListener("load",imageLoadComplete,false);
> }
>
> I'm not familiar with xlink, but if it causes the userAgent to
> synchronously request a resource, the imageLoadProgress won't get
> events.
>
> It seems like it would be necessary to first abort any call, then add  
> listeners:
> // tab-width: 7
> function showImage(imageHref) {
>        var image = document.getElementById('myImage');
> // Pretend we have an "abort()" method that stops loading. Removing
> the href attribute
> // won't stop the load request.
>        image.abort();
>        image.addEventListener("progress",imageLoadProgress,false);
>        image.addEventListener("load",imageLoadComplete,false);
> // Set the href attribute to kick off a synchronous req.
>        image.setAttributeNS(xlinkNS, "href", imageHref);
> }
>
> Is this correct.
>
> Garrett

Received on Sunday, 16 September 2007 15:44:27 UTC