If I host a WebBrowser in my application, and a javascript code in the web page shown on my WebBrowser calls window.close() and I click \"Yes\" on
In WPF you can catch WM_CLOSE message by attaching to WebBrowser's message loop.
public MainWindow()
{
InitializeComponent();
webBrowser.MessageHook += webBrowser_MessageHook;
}
IntPtr webBrowser_MessageHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch(msg)
{
case 0x0010: // WM_CLOSE
handled = true; // cancel event here
// do additional stuff here
break;
}
return IntPtr.Zero;
}