Diese Seite dient Demonstrationszwecken!
×

JS Save Text to File

A simple JS to save text to a file.

function saveTextAsFile(textToWrite, fileNameToSaveAs)
{ var textFileAsBlob = new Blob([ textToWrite], {type:'text/plain'}); var downloadLink = document.createElement(" a" ); downloadLink.download = fileNameToSaveAs; downloadLink.innerHTML = " Download File" ; if (window.webkitURL != null)
{ downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob); }
else
{ downloadLink.href = window.URL.createObjectURL(textFileAsBlob); downloadLink.onclick = destroyClickedElement; downloadLink.style.display = " none" ; document.body.appendChild(downloadLink); }
downloadLink.click(); }