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:

http://jsfiddle.net/uselesscode/qm5ag/


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -