To programmatically trigger a file, located on the server, using JavaScript, here's what I'm currently doing:
HTML
<a id="downloadPDF" href="/my.pdf" download style="display: none;">Download PDF</a>
JavaScript
<script type="text/javascript">
document.getElementById('downloadPDF').click();
</script>
It works, but it feels rather "hackish" to me. Is there a better, more straightforward way of doing it without using HTML and triggering clicks?
Important: No libraries or data URIs. The file should download not open.