Confirm dialog with OK ,CANCEL buttons on window close
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4427714/confirm-dialog-when-i-close-the-browser">Confirm Dialog when i close the browser?</a>  </p>
</blockquote>



<p>i have an aspx page and when i click on browser close button..., the system should check if there is any unsaved data in the form or not. If there is any unsaved data then the message should be displayed (Do you want to leave..?) with OK and Cancel button...
On click of the OK button, the data should not be saved and the user should be returned parent form .On click of the cancel button, the control should return to the page.</p>

<p>I had tried the below code...</p>

<pre><code> window.onbeforeunload = close;
            function close() {
                  var result=confirm("Do you really want to close this window");
                  if (result) {
                        return true;
                  }
                  else {
                        location.href = document.URL;

                  }
               }
</code></pre>

<p>The above code is not working ie the popup is getting closed even on click of closse button....
and when clicked on OK it is dispalying another msgbox with leave this page and Stay on this page buttons...</p>
