JavaScriptでファイルダウンロード

var a = document.createElement('a');
a.download = 'test.txt';
a.href = window.URL.createObjectURL(new Blob( ['test'], {type: 'application/octet-stream'} ));
a.click();