Could we help you? Please click the banners. We are young and desperately need the money
With a little trickery, one can make the browser trigger a file download through JavaScript. The idea is that we virtually create an anchor tag, set its href to the URL of the file, and give it the download attribute. Then we programmatically execute a click upon it using its .click() method.
Here's a function that follows and lets us simplifies this process:
function download(href, filename = '') {
const a = document.createElement('a');
a.href = href;
a.download = filename;
a.click();
}
Usage:
download('https://example.com/foobar.file');