title: Intercept selection in window.onbeforeunload dialog
body: <p>in my web application if the user leaves the current page without having saved changes in the form a pop up window is opened to alert him about that.</p>
  
  <p>For the pop up I use some scripts code injected from codebehind (C#):</p>
  
  <pre><code>var Confirm = true;
  window.onbeforeunload = confirmClose;  
  function confirmClose() 
  {
     if (!Confirm) return;
  
     if(/*CHECK CHANGE CONDITION IS TRUE*/)
        { return " + WARN_message + "; }
  } 
  </code></pre>
  
  <p>I would need to intercept whether the user click on cancel or ok button.</p>
  
  <p>I tried like:</p>
  
  <pre><code>var button_pressed = window.onbeforeunload = confirmClose;
  </code></pre>
  
  <p>But it returns always true. </p>
  
  <p>How can get which button was pressed?
  Thanks</p>