title: Capture the close event of popup window in JavaScript
body: <p>I need to perform some action before a popup window(using <code>window.open</code> ) closes.</p>
  
  <p>Something like will be good:</p>
  
  <pre><code>var new_window = window.open('some url')
  new_window.onBeforeUnload = function(){ my code}
  </code></pre>
  
  <p>How can I achieve that?</p>