Question How can I open the Internet Browser when I click on a link in the WebBrowser control?

Joukuh

New member
Joined
Nov 21, 2013
Messages
4
Programming Experience
1-3
Hello,

In my application I have a WebBrowser control that I use for viewing Html formatted email messages. But when I click on a hyperlink inside the WebBrowser when viewer an email message, the link will be opened inside the webbrowser control. What I actually want is forcing my application to start the Standard Internet Browser (eg. Internet Explorer if u use that as your default internet browser or Google Chrome if that is your standard internet browser etc.) and open the link that was clicked.

Can someone tell me how to accomplish this?

Thanks in Advance,

Best regards,

Joukuh.
 
Handle the Navigating event of the WebBrowser. You can get the URL that it is navigating to and pass it to a call to Process.Start. That will open the default web browser and load that page. You can then cancel the event to prevent navigation within the control.
 
Thanks for your reply, but if I cancel in navigating event the I can't open any other email message anymore...
It's up to you to determine whether you should cancel the event or not and only do so when appropriate. Presumably you can distinguish between the two. That's what 'if' statements are for. If you can't distinguish between the two then how can you expect the program to do so? That would be magic.
 
It's up to you to determine whether you should cancel the event or not and only do so when appropriate. Presumably you can distinguish between the two. That's what 'if' statements are for. If you can't distinguish between the two then how can you expect the program to do so? That would be magic.

Your definatly right! I've done the following to accomplish what I want:

private void HtmlViewer_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if (e.Url.ToString().StartsWith("http"))
{
e.Cancel = true;
MessageBox.Show(e.Url.ToString());
Process.Start(e.Url.ToString());
}
else
{
e.Cancel = false;
}
}And it works :)
 

Latest posts

Back
Top Bottom