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 ");