views:

55

answers:

2

hi

my question is, is that possible to track a download process with javascript or any other else. lets say i want to do some stuff when download finished or cancelled.

is that possible ?

Thanks

+1  A: 

On the client side (ie with javascript) there is no way of doing this, so the answer to your question would be: "You can't"

On the server side I'd say you could if you streamed the output to the client and have some kind of callback at the end. It would need to be done server side.

In pseudo-code:

page.language:

myFile = "/thing.zip"
while !eof
   send a part of the file to the client
   keep track of this
   send to database "it's downloading at x%"
end
send to database "ok it's downloaded"

This depends of your server-side technology and I'm not sure that PHP handles something like this. I did something similar using .NET and it worked fine... it was tricky thought so make sure it's worth doing

marcgg
A: 

If you're trying to have something happen when a object on the page is done downloading (like a large image), then you can use the onLoad event, like this:

<img src="large_image" onload="alert('Large image loaded.');" />

Of course, you can change the behavior in the onLoad event to do whatever you want.

Ben