Search code examples
javascriptjquerypausing-execution

How to pause a function in javascript until a CONDITION is met, not until a defined limit in millisecond is set!


this is urgent and i couldn't find a solution to it. The problem is as follow:

i am designing a web app, which sends multiple commands to multiple machines. Now some of the commands i have require additional input. i have designed a pop up window in jquery that ask user to add this additional input. the problem is while looping through all the commands only a window for the last chosen command pops up... this is because it is not pausing while user enter inputs before going to input to another command.

how can i pause a function from continuing its execution in javascript/jquery?

an example in pseudocode:

loop each command
{
  for selected command popup windows;
  // pause until user finishes input then go to
  // next line where any function is processed

  function(); //then loop again--> pause --> when user finishes continue to function() etc..

}

thx for your help and patience, i tried all kinds of methods without any result. :)


Solution

  • If I understand you correctly, I think you should launch the window using window.showModalDialog() instead of window.open().
    It will hold the execution until the dialog is closed.

    An alternative way is to use the callback function .