mmotor,
function download(filename, text) {
var blob = new Blob([text], {type:'text/csv'}),
link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.setAttribute('download', filename);
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
link.dispatchEvent(event);
}
download('test.txt', 'Hello world! Hello world!');