There are two ways of popup window disposing: manually using Browser.Dispose() method and programmatically from JavaScript using window.close() function. If you use your own implementation of PopupHandler, you must handle the situation when popup window is disposed from JavaScript. Using DisposeEvent you can listen to an event when popup Browser instance is disposed to destroy popup's container. Otherwise, you might have the issue when Browser instance is disposed, but its container is still open and displays gray content.


The following code demonstrates how to handle such situation in your PopupHandler implementation:


WinForms:

C#

browser.DisposeEvent += delegate (object sender, DisposeEventArgs e)
{
    form.BeginInvoke((Action)(() =>
    {
        if(!formClosed)
        {
            form.Controls.Clear();
            form.Hide();
            form.Close();
            formClosed = true;
        }
    }));
};

VB.NET

AddHandler browser.DisposeEvent, Sub(sender, e)
   form.BeginInvoke(Sub()
       If (Not (formClosed)) Then
           form.Controls.Clear()
           form.Hide()
           form.Close()
           formClosed = True
       End If
   End Sub)
End Sub



WPF:

C#

browser.DisposeEvent += delegate(object sender, DisposeEventArgs e)
{
    Application.Current.Dispatcher.Invoke((Action)(() =>
    {
        window.Content = null;
        window.Hide();
        window.Close();
    }));
};

VB.NET

AddHandler browser.DisposeEvent, 
     Sub(sender, e)
        Application.Current.Dispatcher.Invoke(
            Sub()
              window.Content = Nothing
              window.Hide()
              window.Close()
            End Sub)
     End Sub