Download text file javascript

Download text file javascript

by Charles Cavalcante

HTML

<a href="data:text/plain;charset=UTF-8,Hello%20World!" download="hello.txt">Download (static)</a>
<a id="programatically" href="" download="date.txt">Download (dynamic)</a>

JavaScript

$("a#programatically").click(function(){
    var now = new Date().toString();
    this.href = "data:text/plain;charset=UTF-8,"  + encodeURIComponent(now + 'ChárlÊs');
});