0

I have a small form on my page with a button. When the button is clicked, it goes to an MVC controller, which responds with a FileStreamResult.

The user never navigates away from the current tab as such, it stays open - and a download starts of the file my server responds with.

The server can take a good moment or two to generate the file prior to responding - during which I'd like to display a loader in the browser.

Is this something I have access to on the client? This is not an async request but I guess the equivalent of ajax complete would be ideal. i.e. show a spinner, when the server responds, hide the spinner.

Note: I won't tag this as MVC as I believe this is a client-side issue.

1 Answers1

0

You could perhaps rely on the browsers focus events? I'm not sure how reliable this would be in practice.

  1. User clicks link
  2. Listen for browser unfocus
  3. Show your pop up
  4. Remove popup when browser unfocuses (new tab opened, for download)

Relevant:

Detect If Browser Tab Has Focus

Jono20201
  • 3,215
  • 3
  • 20
  • 33
  • Ah, that's a nice idea. I'll have a play about with that. I'd be surprised if the window loses focus as it is, but maybe I can set target to _blank to force it to? –  Sep 20 '18 at 12:57