We help IT Professionals succeed at work.

Javascript how to be sure function executed successfully

Medium Priority
Last Modified: 2013-11-19
My operation takes long time to finish.


function doOperation(){

     //do somethin if something executed successfully then close window. but be sure .

<a href="#" onclick="doOperation();">Do Operation Then Close Window</a>

How can i be sure is my operation finished.

Thanks. Please Help.
Watch Question

HonorGodSoftware Engineer

It depends upon the operation.  There are so many possibilities.

What kind of operation is it?
Javascript is a top-down language.  Meaning, it executes one statement at a time from the top down.  

You could put the window close statement in a second function.  Then at the end of the doOperation function make an if statement testing for a condition that you set if your operation completes.  If it is true, call the close function.  If the operation does not complete, don't set the condition to true, and the close function is not called.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Can you give an example of something you want to do?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.