Answers for "javascript create and download text file"

2

javascript download file from text

function download(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);

  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();

  document.body.removeChild(element);
}

// Start file download.
download("hello.txt","This is the content of my file :)");
Posted by: Guest on March-18-2021
1

js download file from webserver

<iframe id="download_iframe" style="display:none;"></iframe>
<script>
	document.getElementById('download_iframe').src = "/example/example.txt";
</script>
Posted by: Guest on August-03-2020

Code answers related to "javascript create and download text file"

Code answers related to "Javascript"

Browse Popular Code Answers by Language