How to tell if files are downloading






















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? 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. 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.

Do you think that it will, or cookies restrictions will compromise it? Brilliant - it wouldn't have occurred to me in years that you could include cookies as part of a file download. Thank you!! As others have pointed out, this solution only solves part of the problem, the waiting for the server to prepare the file time.

The other part of the problem, which can be considerable depending on the size of the file and the connection speed, is how long it takes to actually get the whole file on the client. And that is not solved with this solution. Show 16 more comments. Echilon 9, 28 28 gold badges silver badges bronze badges. This is a simple approach which is ideal for getting rid of a loading overlay for a file download which was triggered using onbeforeunload Thank you.

Safari, some IE versions, etc. Chrome and other such browsers auto-download the files where this condition will fail. Lucky that is only by default.

It is entirely possible a user of Chrome will specify where downloads should be saved and hence see the dialog box — ESR. Add a comment. Don't eval code inside setTimeout 'getstatus ', ;. Use the fn directly: setTimeout getstatus, ; — Roko C. Jerzy Gebler Jerzy Gebler 9 9 silver badges 13 13 bronze badges.

What if the user clicks the window? The hide is not getting called in my case — Prashant Pimpale. Worked for me for a pdf download with only some line of codes — Chris.

My case is working on JSP and click to download csv. It works. Show 1 more comment. There are four known approaches to dealing with detecting when a browser download starts: Call fetch , retrieve the entire response, attach an a tag with a download attribute, and trigger a click event.

Modern web browsers will then offer the user the option to save the already retrieved file. There are several downsides with this approach: The entire data blob is stored in RAM, so if the file is large, it will consume that much RAM. For small files, this probably isn't a deal breaker. The user has to wait for the entire file to download before they can save it.

They also can't leave the page until it completes. The built-in web browser file downloader is not used. Helpful 1 Not Helpful 1. Helpful 1 Not Helpful 0. Type the name of the file into a search engine such as Google or Yahoo! Try to get yourself a decent anti-virus program on your computer. Norton, AVG and Avast! Even if you just get the free version, it's worth having a defense against a multitude of threats. Type the name of the website on a WHOIS site and it will find you lots of details that help you decide whether you can trust your download.

Helpful 3 Not Helpful 0. If you receive an E-mail from an unknown sender with a file attached, delete it immediately. That has 'virus' written all over it. Helpful 2 Not Helpful 0. Virtual Machines or sandbox programs such as Sandboxie can provide a safe way to test files. Try an add-on, such as VTzilla. It can scan files before you download them and can also scan links.

Try this: Open command prompt. The type the command: ping www. If you use Kaspersky, it is a great idea scanning the file with a virus check before running it - just to be extra sure that your computer isn't at stake! Submit a Tip All tip submissions are carefully reviewed before being published. If you downloaded something suspicious and ran it, download and install an appropriate program to find any threats on your computer. Avast, AVG, or Malwarebytes are good and free programs.

Helpful 18 Not Helpful 9. If you're totally worried and don't know whether you should trust the file or not, don't. There's no point downloading something if you don't trust it.

Some software that looks and is legitimate can actually be hacked. When in doubt, always scan the file for viruses! Related wikiHows How to. How to. About This Article. Tested by:. Co-authors: Updated: March 4, Categories: Internet Security. Nederlands: Weten of het veilig is om iets te downloaden.

Thanks to all authors for creating a page that has been read , times. Is this article up to date? Cookies make wikiHow better.

By continuing to use our site, you agree to our cookie policy. You Might Also Like How to. Featured Articles How to. No account yet? Create an account. Edit this Article. We use cookies to make wikiHow great.

By using our site, you agree to our cookie policy. Cookie Settings. Learn why people trust wikiHow. Download Article Explore this Article methods. Tips and Warnings. Related Articles. Author Info Last Updated: November 5, Method 1. Click on the "Submit a URL" tab and enter the address of the website where you are about to download the file from.

Hit the "Submit URL" button. Virus Scan will check the website for viruses and let you know whether it is safe for downloading files from there or not. Method 2.

Press the "Send file" button. Virus Total will check the download for viruses and let you know of any threats that were detected. Method 3. Use the Browse button to select the download that you want to scan for viruses.



0コメント

  • 1000 / 1000