When using WebBrowser to visit the website, if the site has alert,window.open such as JS, will appear on the desktop pop-up box, and must be dropped to complete access.
I found the internet. The way to block these pop-up boxes is to add event navigated to redefine the functions inside. Like this.
WebBrowser wbwebbrowser = new WebBrowser ();
wbwebbrowser.navigated + = new Webbrowsernavigatedeventhandler (wbwebbrowser_navigated);
......
private void Wbwebbrowser_navigated (object sender, WebBrowserNavigatedEventArgs e)//masking alert and other bullet-frame window cases
{
WebBrowser Wbwebbrowser = (WebBrowser) sender;
StringBuilder sb = new StringBuilder ();
Sb. Appendline ("function alert () {return;}");
Sb. Appendline ("function confirm () {return;}");
Sb. Appendline ("function ShowModalDialog () {return;}");
Sb. Appendline ("function window.open () {return;}");
Sb. Appendline ("function prompt () {return;}");
String strjs = sb. ToString ();
IHTMLWindow2 win = (IHTMLWindow2) WbWebBrowser.Document.Window.DomWindow;
Win.execscript (Strjs, "Javascript");
win = null;
}
I tried on my own computer when I found that there is really an effect, without words to access the pop-up box of the site will pop up content. Add it will not pop up, you can complete the normal access.
But put the generated EXE files on someone else's computer, they will still pop up after running the prompt box. And the system they installed, and the configuration, and the same as on my own computer.
The rule I found at the moment is that it seems that the computer that installs Visual Studio will not pop up like my own computer, and it will bounce if it is not installed, even if they have the. NET Framework.
Excuse me, what's the reason?
I know why, it turns out that the. NET SDK is installed on a machine that comes with Microsoft.mshtml.dll.
On machines that have only the. NET framework installed, you need to
C:\Program files\microsoft.net\primary Interop Assemblies\microsoft.mshtml.dll
In the same directory as the EXE file before you can
WebBrowser Visit website prohibit pop-up windows