Script
function saveAsFile(str, filename) { var hiddenElement = document.createElement('a'); hiddenElement.href = 'data:attachment/text,' + encodeURI(str); hiddenElement.target = '_blank'; hiddenElement.download = filename; hiddenElement.click(); } var strdata = "Hello, world!"; saveAsFile(strdata, "output.txt");
Demo
click: download file