problem of opening a webPage in webBrowser c# control in place of IE control

518 Views Asked by At

For my project I used webBrowser control and when I launch an html site which has got an input(type) button with onclick javascript function which process ending on window.open target="_blank", it's internet explorer window that's is opening in place of a new page of webBrowser.

I program in c# code with winform technology and I used webBrowser System.Windows.Forms.

So which function could I used to open the page of this site in webBrowser window in place of IE window.

Thanks you for your help.

M.A.

2

There are 2 best solutions below

1
On

Read about WebBrowser.Navigating event:

You can handle the Navigating event to cancel navigation if certain conditions have not been met, for example, when the user has not completely filled out a form. To cancel navigation, set the Cancel property of the WebBrowserNavigatingEventArgs object passed to the event handler to true. You can also use this object to retrieve the URL of the new document through the WebBrowserNavigatingEventArgs.Url property.

To open page in default browser, for example:

private void webBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    e.Cancel = true;
    Process.Start(e.Url.ToString());
}
0
On

Finally,

I used the package reference "SHDocVm" of "Microsoft Internet Controls" and I place a function handler NewWindow3 in the function "DocumentCompleted" of webBrowser and it's ok, a window.open() javascript function with target="_blank" opens a new page of webBrowser.

Truly yours.

M.A.