The perfect solution for webbrowser script errors is switched from Hobe

Source: Internet
Author: User

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.