Anuraj TS
Anuraj TS

Reputation: 19

block a popup visual studio

I am using the below code in visual studio to make an auto login software . The software is working fine, But the page that is displayed after login has a popup script. This forces the opening of popup url in internet explorer. I want to block the internet explorer getting opened. Can i solve this ?

private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
{
     webBrowser1.Navigate("https://mwcp-ekm-04.adlkerala.com:8001/");

     webBrowser1.Document.GetElementById("name").InnerText = "name";
     webBrowser1.Document.GetElementById("id").InnerText = "66491";
     webBrowser1.Document.GetElementById("accept").InvokeMember("click");
}

Upvotes: 2

Views: 77

Answers (1)

Alberto
Alberto

Reputation: 15941

You can prevent the opening of a new window (popup) by subscribing to the NewWindow event and then cancel the event itself:

private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
{
    e.Cancel = true;
}

Upvotes: 1

Related Questions