function download() {
var anchor = document.createElement('a');
anchor.setAttribute('href', 'download.txt'); //path
anchor.setAttribute('download', 'download.txt'); //file name
document.body.appendChild(anchor);
anchor.click(); //<a> tag click
anchor.parentNode.removeChild(anchor);
}