Webbrowser was used in the "click my network" hanging-up applet released yesterday. After running the test last night, a problem was found: the script error dialog box pops up when some sites are opened, and the user confirms, in this way, the automatic operation is aborted. I checked online today. Some netizens wrote the current article and learned it.
Note: The Host-mounted program has been updated. Please download it!
Perfect solution for webbrowser script errors
When the IE browser encounters a script error, a yellow icon will appear in the lower-left corner of the browser. You can click to view the detailed information about the script error. No error message box is displayed. When we use the webbrowser control, an error message box is displayed, which shows unfriendly programs and suspends some automatically executed programs. I can see that the solution taken is to create a form killer program to close the pop-up form. The method discussed today is to solve the problem from the control.
1. shdocvw. dll
The webbrowser control we used in the com era is shdocvw. dll. The method for blocking error information is easy to use.
WebBrowser1.Silent = true;
2.. net
In. net, the managed webbrowser is provided for our use. Of course, we can still use com in. Net to build shdocvw. dll. If shdocvw. dll is used
The error handling method is the same as the preceding method. But how can we solve this problem by using the. NET component?
This component provides us with a method scripterrorssuppressed. However, it does not work in. Net framework2.0. It is said that the following solution is used in earlier versions.
webBrowser1.ScriptErrorsSuppressed = true;
(It is said that this was the case before. Net framework2.0 and I have never used it)
So how can we solve this problem in. Net framework2.0?
One method cannot be completely solved. We can solve some of the problems here.
// Capture control errors
This. WebBrowser. Document. Window. Error + = new HtmlElementErrorEventHandler (Window_Error );
// Handle errors
Void Window_Error (object sender, HtmlElementErrorEventArgs e)
{
// Process your own code
E. Handled = true;
}
3. The above method cannot be well solved in the case of nesting multiple frameworks.
To completely solve this problem, we use AxWebBrowser to solve the WebBrowser problem.
We define a class of our own. Its parent class is WebBrowser. We can use this class later. SHDocVw must be referenced in the definition of this class.
Class EWebBrowser: System. Windows. Forms. WebBrowser
{
SHDocVw. IWebBrowser2 Iwb2;
Protected override void AttachInterfaces (object nativeActiveXObject)
{
Iwb2 = (SHDocVw. IWebBrowser2) nativeActiveXObject;
Iwb2.Silent = true;
Base. AttachInterfaces (nativeActiveXObject );
}
Protected override void DetachInterfaces ()
{
Iwb2 = null;
Base. DetachInterfaces ();
}
}