Results 1 to 3 of 3

Thread: How to line break between document.write entries?

  1. #1
    Join Date
    Jul 2011

    How to line break between document.write entries?


    I'm using the script below to list files stored locally on a webpage (I'm developing a small application that is to be loaded from a CD-ROM). It's been done in HTML as per my company's request.

    Essentially, this script works and successfully populates a list of files stored in the folder given by its parameter. However, I wanted a line break between the entries (hence \n) but it doesn't seem to work. I have tried the <pre> tag before and after the div this is printed to, as well as around the script - but it doesn't seem to have any effect. All I get is spaces.

    Do you have any ideas?


    P.S. I had an idea for an alternate solution, if it is an option: perhaps a better way would be to use an unordered list and have a script that adds list items to it? I can't seem to find this anywhere online either.


    function listFiles(thefolder)

    var fso = new ActiveXObject("Scripting.FileSystemObject");

    oFileColl = new Enumerator(bbb.files);
    abc = new Array();

    document.all['listing'].innerHTML = "";

    for (; !oFileColl.atEnd(); oFileColl.moveNext())
    tempp = new String(oFileColl.item());
    name = new String(fso.GetFileName(tempp));
    //Tempp = file location.
    //document.all['listing'].innerHTML += (name.link(tempp)+"\n\n");

    var container = document.getElementById('myList');
    var new_element = document.createElement('li');
    new_element.innerHTML = (name.link(tempp)+"\n");
    container.insertAfter(new_element, container.firstChild);


  2. #2
    Join Date
    Apr 2010
    Cocoa Beach, FL
    I have not validated this yet, but I have similar javascripts on my web applications that set the text content of a div, using the innerHTML property. Usually you have to use html tags to format the text the way that you want. Using document.write is a javascript feature but it is writing text to the HTML scope so you should use HTML in the text you are writing, try writing the line break tag <br> at the end of your sentences and that should help. Also you can enclose your text content in the <p> tag to seperate it from other text content.

    Here is an example that should work, writes a bold font sentence to the browser and ends the sentence with a newline using HTML.

    document.write("<b>This is a test sentence</b><BR>");

    Michael G. Workman

  3. #3
    Join Date
    Jul 2011
    Thanks for the quick reply Michael, I think I tried all of the difficult ways and didn't think that would work. (That did.)

Thread Information

Users Browsing this Thread

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

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