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, and no pop-up error message box will appear. 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.
Copy and save 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.
Copy and save 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.
Copy save // capture control error
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.
Copy and save 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 ();
}
}
You need to add com reference-> com-> Microsoft Internet controls
Http://www.chenjiliang.com/Article/View.aspx? ArticleID = 3148