cursor not stopping until button click completes in window.onbeforeunload?
<p>I have below javascript code for window.onbeforeunload.  I am calling code behind button click method when pressed browser back button. </p>

<p>Now the problem is cursor is not stopping until <code>$("#buttonclientid").click()</code> completes. Just calling the method and moving to next statement. How to hold or stop cursor until <code>$("#buttonclientid").click()</code> complete and then move to next step?</p>

<pre><code>var form_has_been_modified = 0;
  $(function () {

      $("input").keyup(function () {
          form_has_been_modified = 1;
      })
      window.onbeforeunload = function (e) {
          if (!form_has_been_modified) {
                  return;
          }
                doYouWantTo();
      }

   });

   function doYouWantTo(){
        doIt=confirm('Do you want to save the data before leave the page?');
        if (doIt) {
             var returnbutton;
             //cursor should stop here until click function completes.
             returnbutton = $("#buttonclientid").click();
        }
        else{

            }
        }
</code></pre>
