I have a link and, if a user clicks it, I need 2 things to happen:
Content-Type: video/mp4
) I have seen something of the sort with PHP, but is it possible only with HTML/JavaScript?
You might point that to that file with a link. In most browsers, clicking on the link will open the file directly in the browser. But, if you add the download attribute to the link, it will tell the browser to download the file instead.
To trigger a file download on a button click we will use a custom function or HTML 5 download attribute. The download attribute simply uses an anchor tag to prepare the location of the file that needs to be downloaded.
To receive our files URL, we use URL. createObjectURL() which receives our file object as a parameter. Then, specify the name the saved file should have by default with setting the download attribute of the link. Finally, we mount the link in the DOM, click it artificially, and remove it from the DOM.
you can use the download attribute
<a href="http..." download></a>
or specify a filename using
<a href="http..." download="filename.pdf"></a>
see more: https://developer.mozilla.org/en/HTML/element/a#attr-download
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