Quantcast
Channel: textarea content inside a .txt file but keep line-breaks - Stack Overflow
Viewing all articles
Browse latest Browse all 2

textarea content inside a .txt file but keep line-breaks

0
0

I have some piece of code that saves value of textarea into a local text file. Everything is seems to work fine but I don't want to lose line breaks. Code & fiddle:

HTML

<textarea id="textbox">Type something here</textarea> 
<button id="create">Create file</button> 
<a download="info.txt" id="downloadlink" style="display:none">Download</a>

JS

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

    // If we are replacing a previously generated file we need to
    // manually revoke the object URL to 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);

})();

http://jsfiddle.net/qm5AG/562/

Is there some way to keep those line-breaks? Please help me out! Thanks.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images