Detect when the file is done downloading javascript






















That means you will need some unique key for each window. Although generating GUID with jQuery is easy and you can find bunch of functions out there that do that like one in this article, I decided to do it from the back-end using Razor as my app is an ASP. As the solution I used for detecting that long running request was finished relies on cookie values I needed access to cookies on both client ans server side. On server side it is pretty easy to use it out of the box in pretty much any environment, but for client side, I decide to use jquery.

The loop steps are executed on every 1 second after submit an they check whether cookie value is set from the back-end, which automatically means that upload and processing is done from the back-end and it is time to show input form again. While on the server side, beside your logic of generating the response, you need to add one more line before exiting the cod which will set some value to cookie with name sent in windowid hidden field from client side.

This solutions works well with IconExtract web app for now and hopefully if you have some case like this, this should work for you too. Purpose of the code contained in snippets or available for download in this article is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage. He is highly experienced in. He likes working on new technologies and exciting challenging projects.

Figuring out when file download request completes with jQuery. NET Adding display name to Enum values Implementing additional values for Enum items in C. C scripting with. NET Core global tool Using. Post your question to a community of , developers. Sign in Join Now. New Post. Hi all, I googled and read this group but could not find any solution to my problem. I have a page to download big excel files that we 'build' on the server side.

When a user click on the link to download, he has no clue that something is going on and it can take some time. Indeed if the cursor is over some text or some special parts of the page it will not be set to the 'progress' type. Therefore I thought I could just set the cursor type to 'progress' with javascript when the user click and to set it back to default when the download is complete.

Unfortunately it doesn't seem to be possible to know when a download is complete. Could you confirm that? Then, how should I do? Thanks in advance for your help. Follow Post Reply. On Jan 8, pm, barthelemy. If you are using some other way to serve Excel files from the server then a bit of more details are needed. My solution was to use temporary files since I was generating a bunch of temporary files already.

The form is submitted with:. This will cause the load event on the iframe to be fired. Then the wait message is closed and the file download will then start. Tested on IE7 and Firefox.

I'm very late to the party but I'll put this up here if anyone else would like to know my solution:. I had a real struggle with this exact problem but I found a viable solution using iframes I know, I know. It's terrible but it works for a simple problem that I had. I had an html page that launched a separate php script that generated the file and then downloaded it. On the html page, i used the following jquery in the html header you'll need to include a jquery library as well :.

To break this down, jquery first launches your php script in an iframe. The iframe is loaded once the file is generated. Then jquery launches the script again with a request variable telling the script to download the file. The reason that you can't do the download and file generation all in one go is due to the php header function. If you use header , you're changing the script to something other than a web page and jquery will never recognize the download script as being 'loaded'.

I know this may not necessarily be detecting when a browser receives a file but your issue sounded similar to mine. If Xmlhttprequest with blob is not an option then you can open your file in new window and check if eny elements get populated in that window body with interval. If you have download a file, which is saved, as opposed to being in the document, there's no way to determine when the download is complete, since it is not in the scope of the current document, but a separate process in the browser.

If you're streaming a file that you're generating dynamically, and also have a realtime server-to-client messaging library implemented, you can alert your client pretty easily. The server-to-client messaging library I like and recommend is Socket. After your server script is done generating the file that is being streamed for download your last line in that script can emit a message to Socket. On the client, Socket. The benefit of using this method over others is that you are able to detect a "true" finish event after the streaming is done.

For example, you could show your busy indicator after a download link is clicked, stream your file, emit a message to Socket. I realize most people reading answers to this question might not have this type of a setup, but I've used this exact solution to great effect in my own projects and it works wonderfully.



0コメント

  • 1000 / 1000