title: web browser control - detect when js window.close is called
body: <p>I have been searching for many hours but cannot find a working solution.</p>
  
  <p>My c# webbrowser control (part of a winforms app) freezes when a js function is called to close the window. </p>
  
  <p><b>Can I capture a js window.close event?</b></p>
  
  <p>The closest solution I have found is the following but it's just not working (the compiler throws no errors):</p>
  
  <pre><code>HtmlDocument htmlDocument = this.webBrowser1.Document;
  htmlDocument.Window.Unload += new HtmlElementEventHandler(Window_Unload);
  </code></pre>
  
  <p>And the method:</p>
  
  <pre><code>    void Window_Unload(object sender, HtmlElementEventArgs e)
      {
        MessageBox.Show("Display me when webbrowser control is disposed");
      }
  </code></pre>
  
  <p>This is only my second c# program and the first time I have been unable to find a working solution by myself.</p>