Skip to content Skip to sidebar Skip to footer

How Do I Execute Some Javascript After A File Is Downloaded?

I have a page with a link to a file. When the link is clicked I use the code below to show a loading message: $('#TerritoriesToExcelLink').click(function() { $('#TerritoriesToE

Solution 1:

Have your server send a random cookie that you specify from your client-side code with your download in the HTTP headers. Poll in your Javascript to check for the presence of the cookie. This should tell you when the browser has your file.

Solution 2:

If you aren't opposed to using flash...

You could create an invisible flash object on the page, then when you click the download link, you could trigger flash to download the file, then handle the flash download complete event and use the ExternalInterface API to raise the event in javascript.

Solution 3:

This is not possible to do with front end javascript, there is no way for it to retrieve the progress of a download and it doesn't have any events relating to downloads.

I don't think tracking the progress can be done with server side languages either.

Post a Comment for "How Do I Execute Some Javascript After A File Is Downloaded?"