WebBrowser Visit website prohibit pop-up windows

Source: Internet
Author: User

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

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.