Mobe
Mobe

Reputation: 63

Stopping a WebBrowser causes Internet Explorer to be opened

I'm using a C# WebBrowser in order to show a Facebook login dialog for my desktop application. I'm regeistered on the WebBrowser.DocumentCompleted event, and once I get the URL I'm expecting, I stop the WebBrowser, and close the dialog.

For some reason, after closing the dialog, Internet Explorer suddenly opens.

I can only assume that it opens up IE (which is by the way, not even my default browser) because the web server returns the page, and my WebBrowser is already gone. Is that the case? Any idea how to prevent it?

Thanks!

Edit: When I close the WebBrowser, it already contains the HTML that is displayed in the IE.

Upvotes: 6

Views: 2305

Answers (2)

user3626250
user3626250

Reputation: 1

That's because the page did not load successfully. Maybe some script can't be executed by the browser. Before you close WebBrowser or Form, where webBrowser is, open "zero page". Do:

WebBrowser.url = new URl("about:blank");

then close form, close or dispose browser....

Upvotes: 0

Michiko
Michiko

Reputation: 176

If it's a popup. Why not just handle the event? You could do something like this.

{...
  WebBrowser wb = new WebBrowser();
  wb.NewWindow += new System.ComponentModel.CancelEventHandler(wb_NewWindow);
}

void wb_NewWindow(object sender, System.ComponentModel.CancelEventArgs e)
{
    e.Cancel = true;
}

Upvotes: 4

Related Questions