Getting Intermediate Results Reported Right Away

Discussion in 'Javascript' started by Gene Wirchenko, Nov 30, 2011.

  1. Dear JavaScripters:

    I sometimes want to run something for quite some time. An
    example is when I am checking system limits, but later, it could be
    something such as processing transactions.

    I could let it run blind, but especially when testing, that is
    not a good idea. I could put alert()s in, but then I get interrupted
    by them. I would like to be able to start whatever it is going and
    watch (or not).

    How can I simply have JavaScript report as it is executing? Like:
    100 things done
    200 things done
    300 things done
    ...

    Sincerely,

    Gene Wirchenko
     
    Gene Wirchenko, Nov 30, 2011
    #1
    1. Advertisements

  2. Have you ever tried console.log / console.debug? The debugger of your
    choice will be able to show these logs. But don't flood them, that might
    slow down your system!
    Another possiblity is to show a fixed-positioned element on your page (I
    guess you want test in Browser environment) to which you can append your
    logging messages.

    Bergi
     
    Andreas Bergmaier, Nov 30, 2011
    #2
    1. Advertisements

  3. Gene Wirchenko

    Tim Streater Guest

    In Safari, instead of using:

    alert (str);

    you can use:

    console.info (str);

    which puts in the the error console area (Develop -> Show error
    console). If you have that open you can watch the progress.
     
    Tim Streater, Dec 1, 2011
    #3
  4. Gene,

    check http://winhlp.com/node/633 for some hints.

    You have to temporarily halt JavaScript processing to allow the
    browser to render your results to the DOM and then to the
    screen. The article shows ways of how to do that.

    Hans-Georg
     
    Hans-Georg Michna, Dec 1, 2011
    #4
  5. In comp.lang.javascript message <hmddd7litkuobgpjdpstl6hav6clkhr0bl@4ax.
    Choose a browser in which window.status displays, or can be set to, an
    updating status line or part-line while code is running. IE8, Opera
    11.52, Safari 5.1.1, for example.

    Test : for (J=0 ; J<1e6; J++) if (!(J%1e5)) window.status = J


    Choose a browser in which the screen, or a certain element, updates, or
    can be set to, a line while code is running. Testing is easy enough.


    You may cover more browsers by setting both of the above. TIEE.

    Run your code 100 things at a time, with the end of a block writing the
    status to something and starting the next block after a short timeout
    which will allow redraw. You have already been told how to do that.
     
    Dr J R Stockton, Dec 1, 2011
    #5
  6. The way that I have found is to set a timeout and stop execution,
    then continue execution after the timeout has expired. It does make
    for odd-looking code.

    Sincerely,

    Gene Wirchenko
     
    Gene Wirchenko, Dec 1, 2011
    #6
  7. It depends on why you want periodic output.

    When I'm trying stuff out in a browser environment, I might use alert
    boxes for occasional outputs, or form elements for more non-interactive
    output.

    Appending lines of output to a textarea can be useful eg:

    function printScreen(str) {
    document.getElementById("id_of_textarea").value += str + "\n";
    }

    Rgds

    Denis McMahon
     
    Denis McMahon, Dec 1, 2011
    #7
  8. You would. *Any* fairly modern browser (even IE) has or can be augmented
    with an error console that you can print to in various ways, so *none* of
    those kluges are necessary anymore.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Dec 1, 2011
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.