3

After I call the server to get a file, how can I call a javascript function when the dialog for download is shown?

EDIT: My goal is to give the client a feedback when the file is being processed by the server, so events like onclick will not do.

Jose Antonio
  • 444
  • 5
  • 15
  • You'd have to attach a JavaScript function to some specific event, like clicking on a link. AFAIK you can't attach it to something as general as downloading any file. – Blazemonger Dec 19 '11 at 18:09
  • Can you call the function when you "call the server to get a file"? – Jasper Dec 19 '11 at 18:14
  • The problem is I don't know how long is going to take the browser dialog to be shown since the file is being generated in the server, and the client is complaining since there is no feedback... – Jose Antonio Dec 19 '11 at 18:14

2 Answers2

0

Not sure what you are using exactly...

But one of the things you can try is an AJAX based framework like DWR for this.

Basically, you make a call to the server which does some processing and returns control back to client. Now at the client side, you can use callback functions that get called after the server has finished execution.

copenndthagen
  • 49,230
  • 102
  • 290
  • 442
0

You can execute JavaScript when event occurs, full list of event attributes you can find here: http://www.w3schools.com/jsref/dom_obj_event.asp
Unfortunately, you don't have event of showing download dialog.
Instead, you can use for example onclick="jsFunction()" with download links.

Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110