Results 1 to 3 of 3

Thread: New Line using document.write() and document.writeln()

  1. #1
    Join Date
    Jun 2010

    Unhappy New Line using document.write() and document.writeln()

    I am trying to write a bunch of text onto a new document using document.write() and somehow need to format it to include line breaks.

    For example:

    document.write(Line 1);
    document.write(Line 2);
    I have tried including \n, and it does not work. I have also tried document.writeln() and that also does not work.

    From what I have found on the Internet, one (if not both) of those methods should have worked..
    Last edited by irishman101; 07-16-2010 at 10:04 AM.

  2. #2
    Join Date
    Aug 2007
    If you want a new line in HTML, you use <br>. That will work regardless, but depending on the content, maybe you should use <p> for a paragraph or another HTML tag.

    \n is new-line in the sense that after the full stop in my last sentence there is a new line. HTML ignores white space, so that's irrelevant when printing to the browser window.

  3. #3
    Join Date
    Jun 2010

    resolved Problem Resolved!

    I have found advice, that using document.write('<pre>') before the other document.writeln() and document.write('</pre>') at the end formats the text nicely.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center