title: Identifying X close event of a popup window using javascript
body: <p>I need to differentiate between user driven close of a popup window using X close button and close through code.</p>
  
  <pre><code>var win= window.showModelessDialog("http://localhost/test/test.aspx",'google,....);
  //Some manipulations            
  //Manipulation ends
  if(win!=null &amp;&amp; win.open)
  {
   win.close();
  }
  </code></pre>
  
  <p>Now I have full access over test.aspx and test.aspx.cs.I have a onbeforeunload method defined in test.aspx page which will be called either way I close the window(X close or my code gets executed)I basically want to differentiate my X close and programmatic close so that I can do some backend manipulations</p>