html - How to create .txt file using JavaScript / HTML5? -
i new javascript . codes available on internet related create text file using javascript not working in laptop. can give me idea or possible code.
this code should work, give try , if doesn't work may issue browser:
(function () { var textfile = null, maketextfile = function (text) { var data = new blob([text], {type: 'text/plain'}); // if replacing generated file need // manually revoke object url avoid memory leaks. if (textfile !== null) { window.url.revokeobjecturl(textfile); } textfile = window.url.createobjecturl(data); return textfile; }; var create = document.getelementbyid('create'), textbox = document.getelementbyid('textbox'); create.addeventlistener('click', function () { var link = document.getelementbyid('downloadlink'); link.href = maketextfile(textbox.value); link.style.display = 'block'; }, false); })();
and html:
<textarea id="textbox">type here</textarea> <button id="create">create file</button> <a download="info.txt" id="downloadlink" style="display: none">download</a>
taken fiddle:
Comments
Post a Comment