AlgoRythm
AlgoRythm

Reputation: 168

Line breaks in JavaScript string that also save as a .txt

I'm writing a notepad-ish program in HTML, plain JS and CSS. I am currently working on the text saving to an actual file in the user's computer. In short, the script I'm using looks a lot like this:

var textFromPage = document.getElementById("page").value;
var textToWrite = textFromPage;
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});

It basically creates a .txt file from a JavaScript variable, but I want it to look like this:

[[FILENAME]]

[[STYLING CODE]]

[[CONTENT OF PAGE]]

...with those exact line breaks. \n doesn't seem to register when i'm creating the .txt file... any suggestions? D you need more information?

Thanks in advance,

~Dylan

Upvotes: 2

Views: 1857

Answers (1)

meteor
meteor

Reputation: 2568

You need to do something like this

var textToWrite ="file name"+"\r\n" +"Styling Code"+"\r\n"+textFromPage;

Upvotes: 2

Related Questions