msqar
msqar

Reputation: 3020

save text file with javascript using fileSaver.js and Blob.js

don't know if most of you knows about the javascript libraries to save files.

Basically the code used to be the following:

var bb = new BlobBuilder();
bb.append(content);
var fileSaver = window.saveAs(bb.getBlob("text/plain;charset=UTF-8"), "filename.txt");

But now is like this:

var oMyBlob = new Blob([content], { type : "text/plain", endings: "transparent"});
window.saveAs(oMyBlob, "filename.txt");

Either way, whatever i use (if BlobBuilder which is deprecated or Blob), the newLines aren't being displayed, everything is saved under the same line of the text file.

Do you guys know why this is happening? Tried using different ContentTypes: text/plain, text/enricher, text/html...

None of this seems to work with the newLines. If I make an "alert(data)" that i want to save in the file, the newLines are there. When I use this library, looks like it parses the newLines or something, dunno :( Tried another charsets as well..

Thanks in advance.

Upvotes: 1

Views: 6993

Answers (1)

AlphaBetaGamma
AlphaBetaGamma

Reputation: 1930

the "\r\n" char will act as the new line character in your content passed to blob.

Upvotes: 6

Related Questions