However, one of the four methods above will likely be a better fit than the others depending on your use-case. Whenever possible, stream responses to the client on the fly instead of generating everything first on the server and then sending the response. It really depends on finding a library that supports streaming content.
When streaming the response as soon as the request starts, detecting the start of the download won't matter as much because it will start almost right away. Another option is to just output the download headers up front instead of waiting for all of the content to be generated first.
Then generate the content and finally start sending to the client. The user's built-in downloader will patiently wait until the data starts arriving.
The downside is that the underlying network connection could timeout waiting for data to start flowing either on the client or server side. I wrote a simple JavaScript class that implements a technique similar to the one described in bulltorious answer.
I hope it can be useful to someone here. The GitHub project is called response-monitor. By default it uses spin. For more examples check the examples folder on the repository. 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.
My solution with a cookie: - Client side: When submitting your form, call your javascript function to hide your page and load your waiting spinner. If the cookie is found, stop checking every ms, expire the cookie and call your function to come back to your page and remove the waiting spinner removeWaitingSpinner.
It is important to expire the cookie if you want to be able to download another file again! That cookie will be sent to the client when your file will be ready for download. 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. When the user triggers the generation of the file, you could simply assign a unique ID to that "download", and send the user to a page which refreshes or checks with AJAX every few seconds.
Once the file is finished, save it under that same unique ID and If you don't want to generate and store the file on the server, are you willing to store the status, e.
Your "waiting" page could poll the server to know when the file generation is complete. You wouldn't know for sure that the browser started the download but you'd have some confidence. I just had this exact same problem.
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. 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.
BUT onload does not fire in IE for file downloads like with the attachment header token. Polling the server works, but I dislike the extra complexity. So here is what I do:. But really, if your sites that busy the long running process will starve you of threads anyways. A quick solution if you only want to display a message or a loader gif until the download dialog is displayed is to put the message in a hidden container and when you click on the button that generate the file to be downloaded you make the container visible.
Then use jquery or javascript to catch the focusout event of the button to hide the container that contain the message. 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. Then the server-side overrides this cookie with an earlier expiration age -- the completion of the server process. As soon as the cookie expiration is detected in the JS polling, "Loading You can rely on the browser's cache and trigger second download of the same file when the file is loaded to the cache.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Detect when browser receives file download Ask Question.
Asked 12 years, 4 months ago. Active 3 months ago. Viewed k times. Does anyone have a better idea? Improve this question. Riyaz Khan 1, 7 7 silver badges 21 21 bronze badges. Thanks Eric -- that's good to know. I won't waste any more time with that approach. NET folks. Show 2 more comments. Active Oldest Votes. The client algorithm: Generate a random unique token.
Show the "waiting" indicator. Start a timer, and every second or so, look for a cookie named "fileDownloadToken" or whatever you decide. If the cookie exists, and its value matches the token, hide the "waiting" indicator. If it has a non-empty value, drop a cookie e. Improve this answer. David Passmore 6, 4 4 gold badges 43 43 silver badges 68 68 bronze badges.
A heads up for others: if document. For some time I thought the issue was the special 'localhost' domain cookie handling stackoverflow. May be that for others though so worth the read. To use this extension, go to the chrome extensions, download it, and unzip the file and install and activate the developer mode. Keep in mind, browser extensions could look into the pages you browse and even steal your personal data. The Internet is full of reports about that.
Her breakthrough is primarily from generating millions of digital impressions for Entertainment, Blockchain Industry, and various Startups. Home Entertainment How to browse instagram without an account 2 Methods. This way, you can check an your ex, colleague, or see what friends and enemies are up for. The latest outbreak was linked to an elderly couple who were in a group of several tourists.
Dozens of cases have since been linked to their travel, with close contacts in at least five provinces and regions, including the capital Beijing. A vaccine works by mimicking a natural infection. A vaccine not only induces immune response to protect people from any future COVID infection, but also helps quickly build herd immunity to put an end to the pandemic. Herd immunity occurs when a sufficient percentage of a population becomes immune to a disease, making the spread of disease from person to person unlikely.
There are broadly four types of vaccine — one, a vaccine based on the whole virus this could be either inactivated, or an attenuated [weakened] virus vaccine ; two, a non-replicating viral vector vaccine that uses a benign virus as vector that carries the antigen of SARS-CoV; three, nucleic-acid vaccines that have genetic material like DNA and RNA of antigens like spike protein given to a person, helping human cells decode genetic material and produce the vaccine; and four, protein subunit vaccine wherein the recombinant proteins of SARS-COV-2 along with an adjuvant booster is given as a vaccine.
Vaccine development is a long, complex process. Unlike drugs that are given to people with a diseased, vaccines are given to healthy people and also vulnerable sections such as children, pregnant women and the elderly.
So rigorous tests are compulsory. History says that the fastest time it took to develop a vaccine is five years, but it usually takes double or sometimes triple that time. In response, local governments have rolled out mass testing and closed scenic spots and tourist sites, schools and entertainment venues in affected areas, and also imposed targeted lockdowns of housing compounds.
0コメント