js download file button code example
Example 1: download file javascript
function download(link) {
var element = document.createElement('a');
element.setAttribute('href', link);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
Example 2: javascript download file on click
You can trigger a download with the HTML5 download attribute.
<a href="path_to_file" download="proposed_file_name">Download</a>