W3C home > Mailing lists > Public > public-webapi@w3.org > September 2007

Re: Progress Events example

From: Joćo Eiras <joao.eiras@gmail.com>
Date: Sun, 16 Sep 2007 16:44:41 +0100
To: "Garrett Smith" <dhtmlkitchen@gmail.com>, public-webapi@w3.org
Message-ID: <op.tyq7crbxjz3wb9@dragast>



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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:18:58 GMT