I want to trigger a file download using javascript only
I know how to do it with html, but i need to trigger the download specifically with javascript, on a button click.
The reason i am not doing it with html is because i want to use a variable as file name later on.
i have used this
$("#button").click(function(){
window.location = 'files/aaa.pdf';
});
but it only opens the pdf on the same window instead of prompting the user to download it.
I have also tried using this:
<iframe id="my_iframe" style="display:none;"></iframe>
<script>
function Download(url) {
document.getElementById('my_iframe').src = 'files/aa.pdf';
};
</script>
But it fails to produce results.