Search Results

Search found 1 results on 1 pages for 'lambypie'.

Page 1/1 | 1 

  • How to report progress of a JavaScript function?

    - by LambyPie
    I have a JavaScript function which is quite long and performs a number of tasks, I would like to report progress to the user by updating the contents of a SPAN element with a message as I go. I tried adding document.getElementById('spnProgress').innerText = ... statements throughout the function code. However, whilst the function is executing the UI will not update and so you only ever see the last message written to the SPAN which is not very helpful. My current solution is to break the task up into a number of functions, at the end of each I set the SPAN message and then "trigger" the next one with a window.setTimeout call with a very short delay (say 10ms). This yields control and allows the browser to repaint the SPAN with the updated message before starting the next step. However I find this very messy and difficult to follow the code, I'm thinking there must be a better way. Does anyone have any suggestions? Is there any way to force the SPAN to repaint without having to leave the context of the function? Thanks

    Read the article

1