Search This Blog

2017/06/12

Create and download file by JavaScript

Code:
<script>
function download(fileName, content){
    var file = document.createElement('a');
    file.download = fileName;
    file.href = 'data:application/octet-stream,'+encodeURIComponent(content);
    file.click();
}
</script>
Html:
<button onclick="download('test.txt','test text.');"/>

No comments :

Post a Comment