For example: Hi, how are you?
and what I want to write in the txt document:
Hola
que
tal
/* Corrected */
var data = "Hola, \r\n ¿qué \r\n tal?";
var filename = "example_text.txt";
var type = "text/plain;charset=utf-8";
var a = document.createElement("a"),
file = new Blob([data], {type: type});
if (window.navigator.msSaveOrOpenBlob) { // IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
} else { // Others
var url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
Following up on the responses received:
I have tried what you have told me but it continues to put me on the same line
/* Corrected */
var data = "Hola";
data += "\r\n"; // salto de linea
data += "que";
data += "\r\n"; // salto de linea
data += "tal";
var filename = "net_view_cmd.txt";
var type = "text/plain;charset=utf-8";
var a = document.createElement("a"),
file = new Blob([data], {type: type});
if (window.navigator.msSaveOrOpenBlob) // IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
else { // Others
var url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
Some time ago that problem with line breaks in Unix also happened to me, I solved it with
\r\n
probe in Windows and it kept working. Replace in your code\n
by\r\n
, being like this:.
Add
\n
where you want the jump...Ex.
For your example: