When IE browser encounters a script error, a yellow icon appears in the lower left corner of the browser, click to view the details of the script error, and there will be no pop-up error message box. We are writing in the WebBrowser program to open the Web page, encountered a script problem is, will pop up an error box, need to be confirmed before the execution. If the program we are designing is used to automate the processing of Web pages, then when this happens, the program is interrupted and requires manual intervention. This obviously does not meet our requirements.
So what happens when you use WebBrowser to open a Web page and encounter a script error to get the program to run automatically without interfering?
WebBrowser provides us with an attribute: scripterrorssuppressed. You can set this value to True when you do not want to encounter a script error when the error box pops up.
Webbrowser1.scripterrorssuppressed = true;
The specific usage of the Scripterrorssuppressed property is as follows:
Set this property to False to debug the Web page that is displayed in the WebBrowser control. This property is useful if you want to use this control to add WEB-based controls and script code to your application. This property is of little use if the control is used as a generic browser. When you have finished debugging your application, set this property to true to suppress script errors. Http://hovertree.com/h/bjaf/scjyuanma.htm
Note: When scripterrorssuppressed is set to True, the WebBrowser control hides all dialog boxes that originate from the underlying ActiveX control, not just script errors. Sometimes, you may need to suppress script errors when displaying some dialog boxes (for example, a dialog box for browser security settings and user logons). In this case, you should set scripterrorssuppressed to false and suppress the script error in the handler for the Htmlwindow.error event.
The negative effect of this practice as described above, if you want to block only script errors, you can use the following methods:
The following code shows how to suppress a script error without canceling the display of other dialog boxes. In this example, set the Scripterrorssuppressed property to false to ensure that the dialog box is displayed. The handler for the Htmlwindow.error event cancels the display of the error. This event can only be accessed when the document has finished loading, so the handler is attached to the DocumentCompleted event handler.
//Hide script errors only, other errors still promptPrivate voidsuppressscripterrorsonly (WebBrowser browser) {//Make sure that scripterrorssuppressed is set to false. Browser. scripterrorssuppressed =false; //handles the DocumentCompleted event to access the Document object. Browser. DocumentCompleted + =NewWebbrowserdocumentcompletedeventhandler (browser_documentcompleted); } Private voidBrowser_documentcompleted (Objectsender, WebBrowserDocumentCompletedEventArgs e) {((WebBrowser) sender). Document.Window.Error+=NewHtmlelementerroreventhandler (Window_error); } Private voidWindow_error (Objectsender, Htmlelementerroreventargs e) { //ignore the error and suppress the error dialog boxe.handled =true; }/*how to ask Hovertree.com*/
Recommendation: http://www.cnblogs.com/roucheng/p/3521864.html
How to open a webpage with WebBrowser script error