views:

26

answers:

1

hi there

i have a page that generates a report, the report is sent to the browser as an attachment. what i would like to do is .. disable the generate report button , or show a spinny please wait, and when the attachment has finished being generated and has been sent to the browser i'd like to remove the spinny logo/re-enable the button..

is there a js event like, on attachmentcomplete or some such?

thanks

nat

+2  A: 

is there a js event like, on attachmentcomplete or some such?

No. The downloading of files is entirely outside of JavaScript's control.

The only way that comes to mind is having the script that generates the report update some sort of flag (e.g. a temporary file) that you can frequently poll from your page using Ajax. When the script is done generating the data, you would delete the flag.

You'll need to decide if it's worth the effort just for a small UI effect, though.

Pekka
Somebody on Stackoverflow - maybe it was T.J. - once came up with the idea of having the download code set a cookie in the response header, a cookie with a particular random value that the page can poll for.
Pointy
@Pointy hey, nice idea! But it won't be possible to detect when the download *ends* that way, will it?
Pekka
http://stackoverflow.com/questions/1106377/detect-when-browser-receives-file-download/3688765#3688765 : if you want to take the minor feature to the next level
Ravindra Sane