Javascript how to be sure function executed successfully

Posted on 2009-02-18
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.
Question by:phparmy
    LVL 41

    Expert Comment

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

    What kind of operation is it?
    LVL 8

    Accepted Solution

    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.
    LVL 17

    Expert Comment

    Can you give an example of something you want to do?

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now