How can I download a file in a link (say: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png) using javascript?
Edit: I want to download it automatically without any user interaction. There may be a lots of file. And all of them need to be downloaded on page load.
You can use the HTML5 download
attribute, and do it without javascript
<a href="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" download>download file</a>
To make it run without user interaction, you can create the anchor and trigger a click on it with javascript
var a = document.createElement('a');
a.href = "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png";
a.download = 'download';
a.click();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With