The application creates a file:
function download(filename, text) { var element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); element.setAttribute('download', filename); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); } <div id = "div_with_text">some<br/>text</div> <a href = "javascript:download('text.txt', document.getElementById('div_with_text') .textContent)" id = "save" style = "margin-bottom:0px;">save file.</a> However, in the file thus obtained there are no line breaks. Do not tell me, can this be somehow fixed?
<br/>This is anHTMLline break element, in the text it is responsible for\r\n- LamerXaKer<br>first in the receivedjavascriptline and then write to the file.str = str.replaceAll("<br />", "\r\n");- LamerXaKerdocument.getElementById('div_with_text').textContent.replace("<br/>", "\r\n");- LamerXaKer