0

I have a WPF where I am implementing a WebBrowser control and I have a list of objects that when i select them it changes the url binding for the webBrowser control and all is well.

However, if the web page I am on tries to close the Webpage, a dialog pops up where you can hit yes or no to close the "window" (the WebBrowser control)

If the user hits "yes" then the web browser control is closed and exceptions are thrown when you try to select something else in the list because the window doesn't exist anymore.

The webbrowser control does not have a method for closing exposed where i can get to it and I was able to override the "Window.Close()" method but that also prevented me from closing the main app window.

I have tried inheriting from the WebBrowser class but it is sealed so I can't inherit to add event handlers or override methods such as "Close()" or events such as "OnClosing()"

I have no control over the website because it is a third party product.

Also, the WebBrowser control is not cancelling navigation when exiting.

so my question is

A. Is it possible to intercept the dialog and always answer "no"?

or

B. Is there another way to prevent the WebBrowser control from closing even if the person says "yes" to the dialog?

2 Answers 2

1

So, I ended up putting the control in it's separate view and then constructing and destroying the view as a dialogue

0

Once I had to solve a similar situation. It was a Delphi application, with an embedded TWebBrowser component, which is essentially the same thing as the WebBrowser of .NET. The software automatically clicked on elements of the webpage, and there was a case when after the click a confirm dialog popped up. The simplest way to press the OK button automatically was to call FindWindow with the parameters of the confirm dialog, and use the window handle to send it an Enter key press by calling SendInput. I think in your case an Escape key press is needed.

1
  • that seems really hackey and I ended up doing it a little differently anyway. but thanks!
    – timothyswt
    Dec 6, 2011 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.