1. shield the pop-up error script
Set the webbrowser control scripterrorssuppressed to true. (Refer to this blog: http://www.cnblogs.com/qqflying/archive/2012/07/25/2607881.html)
2. Automatic click (blocking) in the pop-up box as soon as the page is loaded)
Private void webbrowserinclunavigated (Object sender, webbrowsernavigatedeventargs E)
{
// Automatically click the pop-up confirmation or prompt
Ihtmldocument2 vdocument = (ihtmldocument2) webbrowser1.document. domdocument;
Vdocument.parentwindow.exe cscript ("function confirm (STR) {return true ;}"," JavaScript "); // pop-up confirmation
Vdocument.parentwindow.exe cscript ("function alert (STR) {return true ;}","Javascript"); // A prompt is displayed.
}
3. After the webbrowser page is loaded, click (Block) in the pop-up box to perform some automated operations on the page)
Private void webbrowserappsdocumentcompleted (Object sender, webbrowserdocumentcompletedeventargs E)
{
// Automatically click the pop-up confirmation or prompt
Ihtmldocument2 vdocument = (ihtmldocument2) webbrowser1.document. domdocument;
Vdocument.parentwindow.exe cscript ("function confirm (STR) {return true ;}"," JavaScript "); // pop-up confirmation
Vdocument.parentwindow.exe cscript ("function alert (STR) {return true ;}"," JavaScript "); // a prompt is displayed.
// The following is your executionCode
}
Note: You must put it in front of your code execution so that the Code will be automatically clicked when a pop-up box exists. If you put this code after you click the button, the prompt box displayed when you click the button cannot be automatically clicked. Click the button and then click the prompt in the dialog box.
In addition, pay attention to reference the using mshtml; naming control.