In a small JavaScript web app, I am using
window.location = '[url]/download-file';
to actually download a file as an attachment. On the server side, I'm using Content-Disposition as 'attachment; filename=xyz.xml' This works great and I'm able to trigger a download on the browser without actually reloading the current page (since it's a single page app, I need to keep the current state of the DOM even after the download is finished.)
However, I would like to show a small ajax loader svg while the file is being downloaded. I have no issue with the logic to display/hide the loader. Where I'm struggling is on how to display the loader when the window.location starts, and hide it once it is resolved (when the browser download prompts appear to save the file.)
Is there an event I could listen to in JavaScript to show/hide the loader when the browser http request starts until the browser http request stops?