7

I have created a multiline string as follows"

var str1 = document.getElementById('text1');
var str2 = document.getElementById('text2');
var str = str1.value + "\n" + str2.value;

I now want to add this string to a div that I create in a popup window as follows:

myWindow=window.open('','Full_text','width=600,height=600');
myWindow.document.write('<div id="div1" style="position: absolute; left: 10px; width: 580px; top: 30px; height: 550px; overflow: auto;">' + str + '</div>');

But I do not get a multiline string in the div. How do I solve this problem?

2 Answers 2

16

Line breaks are not rendered in HTML without this CSS property:

white-space: pre;

You can try to replace str to this:

var str = str1.value + "<br/>\n" + str2.value;
Sign up to request clarification or add additional context in comments.

Comments

4

Line break is not presented when rendering in HTML, if you just need a line break, please use <br> instead of \n If you want to keep white spaces, tabs, you should try to wrap the string with a <pre>string goes here.</pre> tag.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.