This is actually not a solution, but a job, but your question and answer from @Mic led me along this path:
Just use data:text/html so you can put line breaks with <br />
- I tried everything else (all combinations of Unicode characters, etc.) to get line breaks in
text/plain , but couldn't get them to display. document.write() and document.body.textContent() , etc. also suffer from the same problem. Line breaks are simply ignored. - Since Chrome will not allow you to save the popup anyway, the only way to get the text from it is to copy and paste, so there is no benefit in using
text/plain over text/html - In web browsers that allow you to save the page (Firefox), you can save the page as text, not HTML, and therefore you will still get the same end result.
EDIT: This approach works in Chrome, but not in Firefox
win = window.open("", "win") win.document.body.innerText = "Line \n breaks?"
I have to use innerText . InnerHTML or textContent remove line breaks. This works on both:
win = window.open("", "win") win.document.body.innerHTML = "<pre>Line \n breaks?</pre>"
So, maybe you could just wrap everything in <pre> tags? Although I think that both of them have the same "problem" as "
"because it actually creates an HTML document, not a text / plain one.
source share