Webbrowser automatically click the pop-up prompt box alert, pop-up dialog box confirm, shield the pop-up box, shield the pop-up Script Error Solution

Source: Internet
Author: User

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.

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.