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?
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?
Share Improve this question asked Jul 12, 2012 at 9:46 user828647user828647 5151 gold badge10 silver badges29 bronze badges2 Answers
Reset to default 16Line 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;
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.