JAVASCRIPT creating downloadable text file javascript - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution

creating a downloadable text file using javascript


 103

JAVASCRIPT


3

<!DOCTYPE html>
<html>
<head>
</head>
<body>

<textarea id="textarea">Type some text here</textarea>
<button id="create">Create file</button>
<a download="file.txt" id="download_link" style="display: none">Download</a>

<script>
(function () {
var textFile = null,
makeTextFile = function (text) {
var data = new Blob([text], {type: 'text/plain'});

if (textFile !== null) {
window.URL.revokeObjectURL(textFile);
}

textFile = window.URL.createObjectURL(data);

return textFile;
};


var create = document.getElementById('create'),
textarea = document.getElementById('textarea');

create.addEventListener('click', function () {
var link = document.getElementById('download_link');
link.href = makeTextFile(textarea.value);
link.style.display = 'block';
}, false);

})();

</script>
</body>
</html>


By     Created   
The power of the user (%)
63%



The most helpful JAVASCRIPT solutions

How to get client machine name or computer name with javascript ?How to get client machine name or computer name with javascript ?JAVASCRIPT

Click to see more ...

  3.5K     363

get client hostname javascriptget client hostname javascriptJAVASCRIPT

Click to see more ...

  2K     249

detect ie javascriptdetect ie javascriptJAVASCRIPT

Click to see more ...

  1.1K     149

get ip address javascriptget ip address javascriptJAVASCRIPT

Click to see more ...

  639     74

how to create foreach class using javascript ?how to create foreach class using javascript ?JAVASCRIPT

Click to see more ...

  476     69

create qr code javascriptcreate qr code javascriptJAVASCRIPT

Click to see more ...

  443     67

get current url using javascriptget current url using javascriptJAVASCRIPT

Click to see more ...

  275     52

get filename using javascript get filename using javascript JAVASCRIPT

Click to see more ...

  261     45

how to create the connect to a database with ADODB using javascript ?how to create the connect to a database with ADODB using javascript ?JAVASCRIPT

Click to see more ...

  241     43

How replace reverse solidus using javascript ?How replace reverse solidus using javascript ?JAVASCRIPT

Click to see more ...

  236     41