简体   繁体   中英

WPF WebBrowser control. need to prevent it from closing within an app

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?

因此,我最终将控件放入单独的视图中,然后将其构造和销毁为对话框

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM