Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
inserting CrLf in JAVA string does not work
My code
Java
function printpage()
        {
            var originalContents = document.body.innerHTML;
            var printReport = document.getElementById('textbox1').innerHTML;  ///Content to be printed
            printReport = printReport + "\r\n" + 'Adding some other text';
            document.body.innerHTML = printReport;
            window.print();
            document.body.innerHTML = originalContents;
        }


the "\r\n" part is ignored - why? Solution for this problem?
Am running on Windows IIS server.

What I have tried:

printing without CrLf works nicely, but no difference when inserting CrLf. All on same line.
Posted
Updated 10-Oct-20 4:12am
Comments
Richard Deeming 13-Oct-20 8:52am    
NB: Despite the similar names, Java and Javascript are not the same language. You are dealing with a Javascript string, not a Java string.

1 solution

Because HTML doesn't recognise "/r/n" style newlines: try an HTML newline instead:
Java
printReport = printReport + "<br />" + 'Adding some other text';
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900