Reputation: 41
I want to know that how browsers detect that file has been downloaded.I also want to know that can we take control over File Download dialogue through java-script. I have done enough Googling but I didn't get success.Please help me. Thanks in Advance
Upvotes: 0
Views: 392
Reputation: 324630
When downloading a file, the server includes a Content-Length
header indicating how many bytes long the response is. The browser uses this to give you a percentage of completion. You may notice in some cases that this header is missing (generally true of streams, but also exporting files in PHPMyAdmin) and in this case the browser will just tell you how much data has been downloaded so far.
You can use AJAX to download a file, and generally this is used for cache purposes (I use it in my HTML5 games to preload JavaScript files that will be needed later) and in some browsers you can check if the readyState
is 3, then check the length of the responseText
so far against the Content-Length
header to get a percentage - but be warned that some browsers don't like that and will throw an error if you try to access responseText
before readyState
is 4.
Upvotes: 2