开发者

tracking download process with javascript

开发者 https://www.devze.com 2022-12-09 18:07 出处:网络
my question is, is that possible t开发者_开发知识库o track a download process with javascript or any other else. lets say i want to do some stuff when download finished or cancelled.

my question is, is that possible t开发者_开发知识库o 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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消