Reputation: 168
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
Reputation: 2568
You need to do something like this
var textToWrite ="file name"+"\r\n" +"Styling Code"+"\r\n"+textFromPage;
Upvotes: 2