The WebBrowser control shields the alert and confirm script dialog box.

Source: Internet
Author: User

First, select the COM tab in the project reference to add the Microsoft HTML Object Library

Add a reference to the mshtml namespace.

See the code below

 

IHTMLWindow2 win = (IHTMLWindow2) hdoc. Window. DomWindow;
String s = "function confirm (){";
S + = "return true ;";
S + = "}";
S + = "function alert (){}";
Win.exe cScript (s, "javascript ");

 

In this way, the program running process is affected by the message window pop-up in WebBrowser.

A slight modification can also control page navigation. For example, the original alert () method prompts a message, and the modified Code does not have any operations.

If you add a new handler to the modified code, it will be different. When the alert dialog box is displayed, I think the page has been processed.

Now I need to process the next page. In this way, you can add a javascript page Jump script in the curly brackets of function alert.

Modify the Code as follows. You can achieve the desired results. In the following test code, the page is directly navigated to a blank page when the alert method is executed.

 

Code
IHTMLWindow2 win = (IHTMLWindow2) hdoc. Window. DomWindow;
String s = "function confirm (){";
S + = "return true ;";
S + = "}";
S + = "function alert () {window. location. href = 'about: blank ';}";
Win.exe cScript (s, "javascript ");

 

 

 

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.