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

Progress Events example

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Sat, 15 Sep 2007 13:41:29 -0700
Message-ID: <c9e12660709151341w38089f75r65201d6ad4e4ef0a@mail.gmail.com>
To: public-webapi@w3.org

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
-- 
Programming is a collaborative art.
Received on Saturday, 15 September 2007 20:41:33 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 10 December 2014 20:05:34 UTC